Commit graph

7187 commits

Author SHA1 Message Date
bors
a6ece56152 Auto merge of #86400 - FabianWolff:issue-85735, r=estebank
Remove invalid suggestion involving `Fn` trait bound

This pull request closes #85735. The actual issue is a duplicate of #21974, but #85735 contains a further problem, which is an invalid suggestion if `Fn`/`FnMut`/`FnOnce` trait bounds are involved: The suggestion code checks whether the trait bound ends with `>` to determine whether it has any generic arguments, but the `Fn*` traits have a special syntax for generic arguments that doesn't involve angle brackets. The example given in #85735:
```rust
trait Foo {}
impl<'a, 'b, T> Foo for T
where
    T: FnMut(&'a ()),
    T: FnMut(&'b ()), {

    }
```
currently produces:
```
error[E0283]: type annotations needed
   --> src/lib.rs:4:8
    |
4   |       T: FnMut(&'a ()),
    |          ^^^^^^^^^^^^^ cannot infer type for type parameter `T`
    |
    = note: cannot satisfy `T: FnMut<(&'a (),)>`
help: consider specifying the type arguments in the function call
    |
4   |     T: FnMut(&'a ())::<Self, Args>,
    |                     ^^^^^^^^^^^^^^

error: aborting due to previous error
```
which is incorrect, because there is no function call, and applying the suggestion would lead to a parse error. With my changes, I get:
```
error[E0283]: type annotations needed
   --> test.rs:4:8
    |
4   |     T: FnMut(&'a ()),
    |        ^^^^^^^^^^^^^ cannot infer type for type parameter `T`
    |
   ::: [...]/library/core/src/ops/function.rs:147:1
    |
147 | pub trait FnMut<Args>: FnOnce<Args> {
    | ----------------------------------- required by this bound in `FnMut`
    |
    = note: cannot satisfy `T: FnMut<(&'a (),)>`

error: aborting due to previous error
```
i.e. I have added a check to prevent the invalid suggestion from being issued for `Fn*` bounds, while the underlying issue #21974 remains for now.
2021-08-03 19:48:54 +00:00
Fabian Wolff
f8c10ff8b7 Remove invalid suggestion involving Fn trait bound 2021-08-03 21:31:34 +02:00
Fabian Wolff
7c81132a60 Use a multipart suggestion for the parentheses 2021-08-03 21:23:29 +02:00
David Tolnay
3744dc8687
Remove space after negative sign in Literal to_string 2021-08-03 10:40:52 -07:00
bors
c6bc102fea Auto merge of #87515 - crlf0710:trait_upcasting_part2, r=bjorn3
Trait upcasting coercion (part2)

This is the second part of trait upcasting coercion implementation.

Currently this is blocked on #86264 .

The third part might be implemented using unsafety checking

r? `@bjorn3`
2021-08-03 16:58:56 +00:00
Alex Crichton
0168dfec6d Use predefined helper instead of a new one 2021-08-03 07:06:19 -07:00
Alex Crichton
30bc5a936b Move abort_unwinding_calls earlier 2021-08-03 07:06:19 -07:00
Alex Crichton
1c07096a45 rustc: Fill out remaining parts of C-unwind ABI
This commit intends to fill out some of the remaining pieces of the
C-unwind ABI. This has a number of other changes with it though to move
this design space forward a bit. Notably contained within here is:

* On `panic=unwind`, the `extern "C"` ABI is now considered as "may
  unwind". This fixes a longstanding soundness issue where if you
  `panic!()` in an `extern "C"` function defined in Rust that's actually
  UB because the LLVM representation for the function has the `nounwind`
  attribute, but then you unwind.

* Whether or not a function unwinds now mainly considers the ABI of the
  function instead of first checking the panic strategy. This fixes a
  miscompile of `extern "C-unwind"` with `panic=abort` because that ABI
  can still unwind.

* The aborting stub for non-unwinding ABIs with `panic=unwind` has been
  reimplemented. Previously this was done as a small tweak during MIR
  generation, but this has been moved to a separate and dedicated MIR
  pass. This new pass will, for appropriate functions and function
  calls, insert a `cleanup` landing pad for any function call that may
  unwind within a function that is itself not allowed to unwind. Note
  that this subtly changes some behavior from before where previously on
  an unwind which was caught-to-abort it would run active destructors in
  the function, and now it simply immediately aborts the process.

* The `#[unwind]` attribute has been removed and all users in tests and
  such are now using `C-unwind` and `#![feature(c_unwind)]`.

I think this is largely the last piece of the RFC to implement.
Unfortunately I believe this is still not stabilizable as-is because
activating the feature gate changes the behavior of the existing `extern
"C"` ABI in a way that has no replacement. My thinking for how to enable
this is that we add support for the `C-unwind` ABI on stable Rust first,
and then after it hits stable we change the behavior of the `C` ABI.
That way anyone straddling stable/beta/nightly can switch to `C-unwind`
safely.
2021-08-03 07:06:19 -07:00
Brandon H. Gomes
2f85aa6590 remove trailing newline 2021-08-03 09:25:18 -04:00
bors
d5fd37f00f Auto merge of #86338 - JohnTitor:issue-86162, r=estebank
Do not suggest impl traits as type arguments

Fixes #86162
2021-08-03 13:23:31 +00:00
Adam Gemmell
3be9261048 Remove crypto composite feature from allowed aarch64 features.
Prefer using AES/SHA2 features directly.
2021-08-03 12:07:56 +00:00
Giacomo Stevanato
2fd874d0d5 Fix overflow when calculating expected_min in generics diagnostics 2021-08-03 13:18:06 +02:00
Yuki Okushi
b84d08d1e4
Use has_impl_trait where possible 2021-08-03 20:08:16 +09:00
Yuki Okushi
14e92d7116
Do not suggest impl traits as type arguments 2021-08-03 20:05:50 +09:00
bors
2939249f29 Auto merge of #87725 - JohnTitor:rollup-2ywcpuk, r=JohnTitor
Rollup of 8 pull requests

Successful merges:

 - #87645 (Properly find owner of closure in THIR unsafeck)
 - #87646 (Fix a parser ICE on invalid `fn` body)
 - #87652 (Validate that naked functions are never inlined)
 - #87685 (Write docs for SyncOnceCell From and Default impl)
 - #87693 (Add `aarch64-apple-ios-sim` as a possible target to the manifest)
 - #87708 (Add convenience method for handling ipv4-mapped addresses by canonicalizing them)
 - #87711 (Correct typo)
 - #87716 (Allow generic SIMD array element type)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-08-03 10:42:30 +00:00
Kornel
ecb6686914 Expand explanation of E0530 2021-08-03 11:11:17 +01:00
Yuki Okushi
331e78d804
Rollup merge of #87716 - calebzulawski:master, r=workingjubilee
Allow generic SIMD array element type

Fixes the following:
```rust
#[repr(simd)]
struct V<T>([T; 4]);
```

cc ``@workingjubilee``
2021-08-03 19:07:50 +09:00
Yuki Okushi
a14b283022
Rollup merge of #87652 - npmccallum:naked_inline, r=Amanieu
Validate that naked functions are never inlined

Reject all uses of the inline attribute on naked functions.

https://github.com/rust-lang/rfcs/pull/2774
https://github.com/rust-lang/rfcs/pull/2972

cc `@joshtriplett` `@tmiasko` `@Amanieu`
2021-08-03 19:07:44 +09:00
Yuki Okushi
f69daa2617
Rollup merge of #87646 - JohnTitor:fix-parser-ice, r=oli-obk
Fix a parser ICE on invalid `fn` body

Fixes #87635
A better fix would add a check for `fn` body on `expected_one_of_not_found` but I haven't come up with a graceful way. Any idea?
r? ```@oli-obk``` ```@estebank```
2021-08-03 19:07:44 +09:00
Yuki Okushi
345862d224
Rollup merge of #87645 - LeSeulArtichaut:issue-87414, r=oli-obk
Properly find owner of closure in THIR unsafeck

Previously, when encountering a closure in a constant, the THIR unsafeck gets invoked on the owner of the constant instead of the constant itself, producing cycles.
Supersedes #87492. ```@FabianWolff``` thanks for your work on that PR, I copied your test file and added you as a co-author.

Fixes #87414.
r? ```@oli-obk```
2021-08-03 19:07:43 +09:00
Matthias Krüger
02b7754f9e don't use .into() to convert types to identical types (clippy::useless_conversion)
Example:
let _x: String = String::from("hello world").into();
2021-08-03 10:17:57 +02:00
bors
3354a44d2f Auto merge of #87033 - FabianWolff:issue-87017, r=estebank
Provide a suggestion when trying to destructure a `Vec` as a slice

Fixes #87017.

r? `@estebank`
2021-08-03 08:00:30 +00:00
bors
e91405b9d5 Auto merge of #87262 - dtolnay:negative, r=Aaron1011
Support negative numbers in Literal::from_str

proc_macro::Literal has allowed negative numbers in a single literal token ever since Rust 1.29, using https://doc.rust-lang.org/stable/proc_macro/struct.Literal.html#method.isize_unsuffixed and similar constructors.

```rust
let lit = proc_macro::Literal::isize_unsuffixed(-10);
```

However, the suite of constructors on Literal is not sufficient for all use cases, for example arbitrary precision floats, or custom suffixes in FFI macros.

```rust
let lit = proc_macro::Literal::f64_unsuffixed(0.101001000100001000001000000100000001); // :(
let lit = proc_macro::Literal::i???_suffixed(10ulong); // :(
```

For those, macros construct the literal using from_str instead, which preserves arbitrary precision, custom suffixes, base, and digit grouping.

```rust
let lit = "0.101001000100001000001000000100000001".parse::<Literal>().unwrap();
let lit = "10ulong".parse::<Literal>().unwrap();
let lit = "0b1000_0100_0010_0001".parse::<Literal>().unwrap();
```

However, until this PR it was not possible to construct a literal token that is **both** negative **and** preserving of arbitrary precision etc.

This PR fixes `Literal::from_str` to recognize negative integer and float literals.
2021-08-03 04:50:28 +00:00
Caleb Zulawski
b23de51dcb Allow generic SIMD array element type 2021-08-03 03:33:09 +00:00
Brandon H. Gomes
a77d6ff359 add long error explanation for E0625 2021-08-02 23:03:16 -04:00
Nathaniel McCallum
157e0a0e8f Validate that naked functions are never inlined
Reject all uses of the inline attribute on naked functions.

rust-lang/rfcs#2774
rust-lang/rfcs#2972
2021-08-02 21:49:51 -04:00
bors
f63ab6cfa2 Auto merge of #87628 - estebank:unmet-explicit-lifetime-bound, r=oli-obk
Point at unmet explicit lifetime obligation bound

r? `@oli-obk`

Split off of #85799.
2021-08-02 23:16:40 +00:00
Charles Lew
a1cff1cd49 Small refactorings for miri. 2021-08-03 01:09:37 +08:00
Charles Lew
63ed625313 Implement pointer casting. 2021-08-03 01:09:37 +08:00
bors
6be8a06bcf Auto merge of #87698 - camsteffen:rollup-yvjfc26, r=camsteffen
Rollup of 6 pull requests

Successful merges:

 - #86176 (Implement a `explicit_generic_args_with_impl_trait` feature gate)
 - #87654 (Add documentation for the order of Option and Result)
 - #87659 (Fix invalid suggestions for non-ASCII characters in byte constants)
 - #87673 (Tweak opaque type mismatch error)
 - #87687 (Inline some macros)
 - #87690 (Add missing "allocated object" doc link to `<*mut T>::add`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-08-02 15:54:11 +00:00
Guillaume Gomez
c364a4e30f Assign E0784 to union expression error 2021-08-02 16:51:39 +02:00
Cameron Steffen
87a99c5949
Rollup merge of #87687 - camsteffen:inline-macros, r=oli-obk
Inline some macros

I factored out some macros that are not really necessary.
2021-08-02 09:36:54 -05:00
Cameron Steffen
1b48f4d1ea
Rollup merge of #87673 - estebank:opaque-ty-mismatch, r=davidtwco
Tweak opaque type mismatch error
2021-08-02 09:36:52 -05:00
Cameron Steffen
4380056397
Rollup merge of #87659 - FabianWolff:issue-87397, r=davidtwco
Fix invalid suggestions for non-ASCII characters in byte constants

Fixes #87397.
2021-08-02 09:36:51 -05:00
Cameron Steffen
14f3418f79
Rollup merge of #86176 - nbdd0121:explicit-generic-args, r=jackh726
Implement a `explicit_generic_args_with_impl_trait` feature gate

Implements #83701

When this gate is enabled, explicit generic arguments can be specified even if `impl Trait` is used in argument position. Generic arguments can only be specified for explicit generic parameters but not for the synthetic type parameters from  `impl Trait`

So code like this will be accepted:
```rust
#![feature(explicit_generic_args_with_impl_trait)]

fn foo<T: ?Sized>(_f: impl AsRef<T>) {}
fn main() {
    foo::<str>("".to_string());
}
```
2021-08-02 09:36:49 -05:00
bors
3227e35765 Auto merge of #87248 - RalfJung:ctfe-partial-overwrite, r=oli-obk
CTFE: throw unsupported error when partially overwriting a pointer

Currently, during CTFE, when a write to memory would overwrite parts of a pointer, we make the remaining parts of that pointer "uninitialized". This is probably not what users expect, so if this ever happens they will be quite confused about why some of the data just vanishes for seemingly no good reason.
So I propose we change this to abort CTFE when that happens, to at last avoid silently doing the wrong thing.
Cc https://github.com/rust-lang/rust/issues/87184

Our CTFE test suite still seems to pass. However, we should probably crater this, and I want to do some tests with Miri as well.
2021-08-02 13:31:02 +00:00
Alexis Bourget
690cbb79b3 Better message for invalid keyword placement in fn
After this commit, `unsafe async fn ...` now suggests the `async unsafe` fix
instead of misunderstanding the issue.

This is not perfect for repeated keywords (`const async const`) and for
keywords that are misplaced after `extern "some abi"` because of the way
`check_fn_font_matter` works, but changing it breaks so many tests and
diagnostics it has been judged too high a cost for this PR.
2021-08-02 11:10:19 +02:00
bors
b53a93db2d Auto merge of #87535 - lf-:authors, r=Mark-Simulacrum
rfc3052 followup: Remove authors field from Cargo manifests

Since RFC 3052 soft deprecated the authors field, hiding it from
crates.io, docs.rs, and making Cargo not add it by default, and it is
not generally up to date/useful information for contributors, we may as well
remove it from crates in this repo.
2021-08-02 05:49:17 +00:00
Gary Guo
9b90e7e980 Implement a explicit_generic_args_with_impl_trait feature gate
When this gate is enabled, explicit generic arguments can be specified even
if `impl Trait` is used in argument position. Generic arguments can only be
specified for explicit generic parameters but not for the synthetic type
parameters from  `impl Trait`
2021-08-02 04:17:01 +01:00
Yuki Okushi
5cf6566df4
Rollup merge of #87608 - Aaron1011:remove-system-library, r=Mark-Simulacrum
Remove unused field `Session.system_library_path`
2021-08-02 11:03:27 +09:00
Cameron Steffen
02cd72e34b Inline make_if macro 2021-08-01 17:46:28 -05:00
Cameron Steffen
8746b79a38 Inline create_maybe_get_coercion_reason macro 2021-08-01 17:46:23 -05:00
bors
2827db2b13 Auto merge of #87622 - pietroalbini:bump-bootstrap, r=Mark-Simulacrum
Bump bootstrap compiler to 1.55

Changing the cfgs for stdarch is missing, but my understanding is that we don't need to do it as part of this PR?

r? `@Mark-Simulacrum`
2021-08-01 19:04:37 +00:00
Pietro Albini
24f9de5a44 bump bootstrap compiler to 1.55 2021-08-01 11:19:24 -04:00
bors
2e9c8705e9 Auto merge of #87664 - devnexen:netbsd_sanitizers_support, r=nagisa
netbsd x86_64 arch enable supported sanitizers.
2021-08-01 14:16:37 +00:00
bors
8d57c0ab2b Auto merge of #87546 - rusticstuff:issue87450-take-two, r=davidtwco
Bail on any found recursion when expanding opaque types

Fixes #87450. More of a bandaid because it does not fix the exponential complexity of the type folding used for opaque type expansion.
2021-08-01 11:56:02 +00:00
bors
aadd6189ad Auto merge of #87449 - matthiaskrgr:clippyy_v2, r=nagisa
more clippy::complexity fixes

(also a couple of clippy::perf fixes)
2021-08-01 09:15:15 +00:00
bors
4e282795d7 Auto merge of #87662 - FabianWolff:rb-string, r=estebank
Suggest `br` if the unknown string prefix `rb` is found

Currently, for the following code:
```rust
fn main() {
    rb"abc";
}
```
we issue the following suggestion:
```
help: consider inserting whitespace here
  |
2 |     rb "abc";
  |       --
```
With my changes (only in edition 2021, where unknown prefixes became an error), I get:
```
help: use `br` for a raw byte string
  |
2 |     br"abc";
  |     ^^
```
2021-07-31 20:20:18 +00:00
Fabian Wolff
c29aadd9cf Provide a suggestion when trying to destructure a Vec as a slice 2021-07-31 21:47:36 +02:00
Esteban Küber
052084af13 Tweak opaque type mismatch error 2021-07-31 12:20:00 -07:00
Fabian Wolff
470cbc0e2e Require parentheses to avoid confusions around labeled break and loop expressions 2021-07-31 19:10:58 +02:00
Michael Hackner
32992357eb Allow more "unknown argument" strings from linker
Some toolchains emit slightly different errors, e.g.

    ppc-vle-gcc: error: unrecognized option '-no-pie'
2021-07-31 09:35:55 -07:00
Vadim Petrochenkov
b08576b2ad rustc: Replace HirIds with LocalDefIds in AccessLevels tables
and passes using them - primarily privacy checking, stability checking and dead code checking.

WIP
2021-07-31 19:31:29 +03:00
Esteban Küber
e5d42af6ba Point at unmet explicit lifetime obligation bound 2021-07-31 07:56:01 -07:00
David Carlier
4258e937f6 netbsd x86_64 arch enable supported sanitizers. 2021-07-31 15:26:55 +01:00
bors
337181e07d Auto merge of #87607 - JohnTitor:help-to-unused-must-use-op, r=estebank
Add a hint that the expressions produce a value

Fixes #85913
The second commit is semi-_unrelated_ but it allows us to run the related tests just on `src/test/ui/lint`.
2021-07-31 13:47:25 +00:00
Fabian Wolff
f2c9654dcd Suggest br if the unknown string prefix rb is found 2021-07-31 15:37:36 +02:00
Fabian Wolff
c1abb6f4d6 Fix invalid suggestions for non-ASCII characters in byte constants 2021-07-31 15:21:11 +02:00
Ralf Jung
b7b5091378 typo
Co-authored-by: Oli Scherer <github35764891676564198441@oli-obk.de>
2021-07-31 11:30:35 +02:00
Ralf Jung
14de6ec8d8 CTFE: throw unsupported error when partially overwriting a pointer 2021-07-31 11:30:33 +02:00
bors
7069a8c2b7 Auto merge of #86264 - crlf0710:trait_upcasting_part1, r=nikomatsakis
Trait upcasting coercion (part1)

This revives the first part of earlier PR #60900 .

It's not very clear to me which parts of that pr was design decisions, so i decide to cut it into pieces and land them incrementally. This allows more eyes on the details.

This is the first part, it adds feature gates, adds feature gates tests, and implemented the unsize conversion part.
(I hope i have dealt with the `ExistentialTraitRef` values correctly...)

The next part will be implementing the pointer casting.
2021-07-31 07:46:14 +00:00
bors
199d1aebe4 Auto merge of #86754 - estebank:use-multispans-more, r=varkor
Use `multipart_suggestions` more

Built on top of #86532
2021-07-30 23:18:12 +00:00
Yuki Okushi
924eddf30d
Apply review suggestion 2021-07-31 06:21:52 +09:00
Yuki Okushi
eaff0fc25b
Add a hint that the expressions produce a value 2021-07-31 06:12:42 +09:00
Yuki Okushi
d2d851949b
Fix a parser ICE on invalid fn body 2021-07-31 06:09:54 +09:00
bors
1f0a591b3a Auto merge of #87640 - JohnTitor:rollup-yq24nq5, r=JohnTitor
Rollup of 9 pull requests

Successful merges:

 - #86072 (Cross compiling rustc_llvm on Darwin requires zlib.)
 - #87385 (Make `SEMICOLON_IN_EXPRESSIONS_FROM_MACROS` warn by default)
 - #87547 (Add missing examples for NonNull)
 - #87557 (Fix issue with autofix for ambiguous associated function from Rust 2021 prelude when struct is generic)
 - #87559 (Tweak borrowing suggestion in `for` loop)
 - #87596 (Add warning when whitespace is not skipped after an escaped newline)
 - #87606 (Add some TAIT-related regression tests)
 - #87609 (Add docs about performance and `Iterator::map` to `[T; N]::map`)
 - #87616 (Fix missing word in rustdoc book)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-07-30 19:45:55 +00:00
Yuki Okushi
aa9e6aa8ad
Rollup merge of #87596 - jesyspa:issue-87318-hidden-whitespace, r=estebank
Add warning when whitespace is not skipped after an escaped newline

Fixes issue #87318, also simplifies issue #87319.

* Add support to the lexer to emit warnings as well as errors.
* Emit a warning when a string literal contains an escaped newline, but when (some of) the whitespace on the next line is not skipped due to it being non-ASCII.
2021-07-31 04:09:31 +09:00
Yuki Okushi
5e2655d27f
Rollup merge of #87559 - estebank:consider-borrowing, r=oli-obk
Tweak borrowing suggestion in `for` loop
2021-07-31 04:09:30 +09:00
Yuki Okushi
fb27c4cc70
Rollup merge of #87557 - rylev:fix-invalid-prelude-collision-error, r=nikomatsakis
Fix issue with autofix for ambiguous associated function from Rust 2021 prelude when struct is generic

Fixes #86940

The test cases and associated issue should make it clear what specifically this is meant to fix. The fix is slightly hacky in that we check against the literal source code of the call site for the presence of `<` in order to determine if the user has included the generics for the struct (meaning we don't need to include them for them).

r? ``@nikomatsakis``
2021-07-31 04:09:29 +09:00
Yuki Okushi
f6bc738433
Rollup merge of #87385 - Aaron1011:final-enable-semi, r=petrochenkov
Make `SEMICOLON_IN_EXPRESSIONS_FROM_MACROS` warn by default

This PR makes the `SEMICOLON_IN_EXPRESSIONS_FROM_MACROS` lint warn by default.

To avoid showing a large number of un-actionable warnings to users, we only enable the lint for macros defined in the same crate. This ensures that users will be able to fix the warning by simply removing a semicolon.

In the future, I'd like to enable this lint unconditionally, and eventually make it into a hard error in a future edition. This PR is a step towards that goal.
2021-07-31 04:09:20 +09:00
Yuki Okushi
9391d55204
Rollup merge of #86072 - MarcusCalhoun-Lopez:llvm_cross, r=nagisa
Cross compiling rustc_llvm on Darwin requires zlib.
2021-07-31 04:09:19 +09:00
bors
ef9549b6c0 Auto merge of #87421 - estebank:perf-run, r=oli-obk
Do not discard `?Sized` type params and suggest their removal
2021-07-30 17:18:50 +00:00
LeSeulArtichaut
12804230a2 Properly find owner of closure in THIR unsafeck
Co-authored-by: FabianWolff <fabian.wolff@alumni.ethz.ch>
2021-07-30 19:05:34 +02:00
Charles Lew
fb4e0a0972 Implement trait upcasting coercion type-checking. 2021-07-31 00:51:39 +08:00
Charles Lew
ac354cf5ce Add feature gate tests. 2021-07-31 00:51:38 +08:00
Alexander Regueiro
2dc86a6450 Added feature gate. 2021-07-31 00:51:38 +08:00
Esteban Küber
0b8f192cfe Use multispan suggestions more often
* Use more accurate span for `async move` suggestion
* Use more accurate span for deref suggestion
* Use `multipart_suggestion` more often
2021-07-30 09:26:31 -07:00
Esteban Küber
17b2f92e44 Tweak borrowing suggestion in for loop 2021-07-30 08:59:42 -07:00
Esteban Küber
15a40c7ee8 Do not discard ?Sized type params and suggest their removal 2021-07-30 08:44:31 -07:00
Ryan Levick
578fcbdb3c Fix error with suggestion for how to disambiguate associated function when struct is generic 2021-07-30 17:18:43 +02:00
bors
f3f8e758f2 Auto merge of #85971 - FabianWolff:issue-85586, r=davidtwco
Use more precise span for E0282 in cast expressions

This pull request fixes #85586. The example code given there:
```rust
fn main() {
    let a = [1, 2, 3].iter().sum();
    let b = (a + 1) as usize;
}
```
currently produces
```
error[E0282]: type annotations needed
 --> issue-85586.rs:3:13
  |
3 |     let b = (a + 1) as usize;
  |             ^^^^^^^^^^^^^^^^ cannot infer type
  |
  = note: type must be known at this point

error: aborting due to previous error
```
even though the type of the entire cast expression quite clearly should be `usize`. The error is in the cast's left-hand side, which is made explicit by the changes in this PR:
```
error[E0282]: type annotations needed
 --> issue-85586.rs:3:13
  |
3 |     let b = (a + 1) as usize;
  |             ^^^^^^^ cannot infer type
  |
  = note: type must be known at this point

error: aborting due to previous error
```
2021-07-30 14:38:00 +00:00
Anton Golov
5d59b4412e Add warning when whitespace is not skipped after an escaped newline. 2021-07-30 16:26:39 +02:00
bors
87dc824248 Auto merge of #87237 - jonas-schievink:const-for-and-try, r=oli-obk
Add feature gates for `for` and `?` in consts

These operations seems *relatively* straightforward to support, and only seem to be blocked on `impl const Trait`.

I have included a working test for `const_try`, but `const_for` is currently unusable without reimplementing *every single* defaulted `Iterator` method, so I didn't do that.

(both features still need tracking issues before this is merged)
2021-07-30 12:05:48 +00:00
bors
1195bea5a7 Auto merge of #87615 - JohnTitor:rollup-t5jpmrg, r=JohnTitor
Rollup of 10 pull requests

Successful merges:

 - #87052 (Optimize fmt::PadAdapter::wrap)
 - #87522 (Fix assert in diy_float)
 - #87553 (Fix typo in rustc_driver::version)
 - #87554 (2229: Discr should be read when PatKind is Range)
 - #87564 (min_type_alias_impl_trait is going to be removed in 1.56)
 - #87574 (Update the examples in `String` and `VecDeque::retain`)
 - #87583 (Refactor compression cache in v0 symbol mangler)
 - #87585 (Add missing links for core::char types)
 - #87594 (fs File get_path procfs usage for netbsd same as linux.)
 - #87602 ([backtraces]: look for the `begin` symbol only after seeing `end`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-07-30 09:43:32 +00:00
Yuki Okushi
1757d6b34d
Rollup merge of #87583 - tmiasko:compression-cache, r=wesleywiser
Refactor compression cache in v0 symbol mangler

* Remove redundant option around compression caches (they are always present).
* Flatten compression caches into symbol mangler to avoid dynamic memory allocation.
* Implement printer for `&mut SymbolMangler` instead of `SymbolMangler` to avoid passing now slightly larger symbol mangler by value.
2021-07-30 16:26:58 +09:00
Yuki Okushi
55ce7ed5f2
Rollup merge of #87564 - spastorino:adjust-min-tait-removed-version, r=jackh726
min_type_alias_impl_trait is going to be removed in 1.56

#87501 removed `min_type_alias_impl_trait` but meanwhile that PR was approved in homu queue, a new beta was cut so we need to bump the version because it won't be removed in 1.55.

r? ```@oli-obk```

```@bors``` rollup=always
2021-07-30 16:26:56 +09:00
Yuki Okushi
aaef1a1649
Rollup merge of #87554 - sexxi-goose:fix-issue-87426, r=nikomatsakis
2229: Discr should be read when PatKind is Range

This PR fixes an issue related to pattern matching in closures when Edition 2021 is enabled.

- If any of the patterns the discr is being matched on is `PatKind::Range` then the discr should be read

r? ```@nikomatsakis```

Closes https://github.com/rust-lang/rust/issues/87426
2021-07-30 16:26:55 +09:00
Yuki Okushi
7e4b1737ff
Rollup merge of #87553 - bjorn3:fix_hotplug_codegen_version, r=wesleywiser
Fix typo in rustc_driver::version

This caused rustc `-Zcodegen-backend=foo.so -vV` to look for `oo.so` instead of `foo.so`
2021-07-30 16:26:54 +09:00
bors
f739552870 Auto merge of #87483 - oli-obk:tait_ice, r=lqd
Mir borrowck does not generate lifetime variables for 'static lifetimes during opaque type resolution

Fixes #87455

This situation was unreachable before #87287 as we used to just grab the resolved opaque type from typeck and replaced all regions with new inference vars. After #87287 we let the `InferCx` in mir borrowck figure out the opaque type all by itself (which it already did before, but it only used the result to sanity check with the typeck result).
2021-07-30 07:02:34 +00:00
Jonas Schievink
c5a29f9245 Update error code description 2021-07-30 00:33:30 +02:00
Aaron Hill
377b4ce2b9
Remove unused field Session.system_library_path 2021-07-29 16:56:50 -05:00
Jade
3cf820e17d rfc3052: Remove authors field from Cargo manifests
Since RFC 3052 soft deprecated the authors field anyway, hiding it from
crates.io, docs.rs, and making Cargo not add it by default, and it is
not generally up to date/useful information, we should remove it from
crates in this repo.
2021-07-29 14:56:05 -07:00
Jonas Schievink
4ee1840c0c Add tracking issues 2021-07-29 23:21:54 +02:00
Jonas Schievink
dbd126901a Add feature gates for for and ? in consts 2021-07-29 23:21:54 +02:00
Tomasz Miąsko
0eabbf84ba Implement Printer for &mut SymbolMangler
to avoid passing the symbol mangler by value.
2021-07-29 13:30:40 +02:00
Tomasz Miąsko
0ce8001a47 Flatten compression caches into symbol mangler
The compression caches currently don't have any dedicated functionality
that would benefit from being separated. Incorporating caches directly
into the symbol manger also avoids dynamic memory allocation.

The symbol mangler, which is often passed by value, is now slightly
larger. This aspect will be addressed by a follow-up commit.
2021-07-29 13:28:08 +02:00
Tomasz Miąsko
8307072edf Remove redundant option around compression caches
Compression caches are always present. Remove unnecessary option.
2021-07-29 13:28:04 +02:00
Tomasz Miąsko
38c07c7ca5 Implement Printer for &mut SymbolPrinter
to avoid passing `SymbolPrinter` by value.
2021-07-29 13:21:20 +02:00
bjorn3
2f6662da85 Use strip_prefix 2021-07-29 11:54:39 +02:00
bors
6e0a8bf790 Auto merge of #86998 - m-ou-se:const-panic-fmt-as-str, r=oli-obk
Make const panic!("..") work in Rust 2021.

During const eval, this replaces calls to core::panicking::panic_fmt and std::panicking::being_panic_fmt with a call to a new const fn: core::panicking::const_panic_fmt. That function uses fmt::Arguments::as_str() to get the str and calls panic_str with that instead.

panic!() invocations with formatting arguments are still not accepted, as the creation of such a fmt::Arguments cannot be done in constant functions right now.

r? `@RalfJung`
2021-07-29 07:12:07 +00:00
bors
581b1664c9 Auto merge of #87416 - Aaron1011:query-side-effect, r=cjgillot
Create `QuerySideEffects` and use it for diagnostics

The code for saving and loading diagnostics during execution is generalized to handle a new `QuerySideEffects` struct. Currently, this struct just holds diagnostics - in a follow-up PR, I plan to add support for storing attriutes marked as used during query execution.

This is a pure refactor, with no intended behavior changes.
2021-07-29 02:51:19 +00:00
Yuki Okushi
9e94d7bbe6
Rollup merge of #87527 - LeSeulArtichaut:no-mir-unsafeck, r=oli-obk
Don't run MIR unsafeck at all when using `-Zthir-unsafeck`

I don't know how I missed this :D
r? ``@oli-obk``
2021-07-29 06:11:48 +09:00
Yuki Okushi
1d5f15f9fb
Rollup merge of #87521 - midgleyc:long-E0498, r=GuillaumeGomez
Add long explanation for E0498

Helps with #61137
2021-07-29 06:11:47 +09:00
Yuki Okushi
9222984636
Rollup merge of #87435 - ibraheemdev:patch-4, r=JohnTitor
fix example code for E0617

Closes #86908
2021-07-29 06:11:44 +09:00
Ibraheem Ahmed
00198dd902 fix example code for E0617 2021-07-28 16:33:02 -04:00
Santiago Pastorino
cf5e48d944
min_type_alias_impl_trait is going to be removed in 1.56 2021-07-28 17:04:45 -03:00
bors
a28109a767 Auto merge of #87540 - JohnTitor:rollup-8xc6bl5, r=JohnTitor
Rollup of 10 pull requests

Successful merges:

 - #87315 (Add docs for raw-dylib to unstable book)
 - #87330 (Use hashbrown's `extend_reserve()` in `HashMap`)
 - #87443 (Don't treat git repos as non-existent when `ignore_git` is set)
 - #87453 (Suggest removing unnecessary &mut as help message)
 - #87500 (Document math behind MIN/MAX consts on integers)
 - #87501 (Remove min_type_alias_impl_trait in favor of type_alias_impl_trait)
 - #87507 (SGX mutex is *not* moveable)
 - #87513 (bootstrap.py: change `git log` option to indicate desired behavior)
 - #87523 (Stop creating a reference then immediately dereferencing it.)
 - #87524 (Fix ICE in `diagnostic_hir_wf_check`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-07-28 16:59:00 +00:00
Roxane
d380ed1304 fix nit 2021-07-28 12:27:57 -04:00
Roxane
9829efb892 Range PatKind implies discr should be read 2021-07-28 10:52:39 -04:00
bjorn3
cd6c0e4e3b Fix typo in rustc_driver::version
This caused rustc -Zcodegen-backend=foo.so -vV to look for oo.so instead of
foo.so
2021-07-28 16:36:01 +02:00
Mara Bos
0b8033ad8d Improve comments about const panic handling
Co-authored-by: Ralf Jung <post@ralfj.de>
2021-07-28 16:18:38 +02:00
Mara Bos
4e6356188f Check that const_panic_fmt is const too. 2021-07-28 16:18:38 +02:00
Mara Bos
b64c4f9560 Add new const_format_args!() macro and use it in panics. 2021-07-28 16:12:25 +02:00
Mara Bos
f827d3e285 Make const panic!("..") work in Rust 2021.
During const eval, this replaces calls to core::panicking::panic_fmt and
std::panicking::being_panic_fmt with a call to a new const fn:
core::panicking::const_panic_fmt. That function uses
fmt::Arguments::as_str() to get the str and calls panic_str with that
instead.

panic!() invocations with formatting arguments are still not accepted,
as the creation of such a fmt::Arguments cannot be done in constant
functions right now.
2021-07-28 16:10:41 +02:00
Hans Kratz
aa465a5983 Bail on any found recursion when expanding opaque types
Fixes #87450. More of a bandaid because it does not fix the exponential complexity of the type folding used for opaque type expansion.
2021-07-28 14:21:59 +02:00
Yuki Okushi
7985e4c7c3
Rollup merge of #87524 - FabianWolff:issue-87495, r=Aaron1011
Fix ICE in `diagnostic_hir_wf_check`

Fixes #87495. The [documentation for `ObligationCauseCode::WellFormed`](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_infer/traits/enum.ObligationCauseCode.html#variant.WellFormed) says that

> it is always correct [...] to specify `WellFormed(None)`

instead of `WellFormed(Some(...))`, which seems to have caused the issue here, as `diagnostic_hir_wf_check` does not expect to be called with an associated constant and will ICE:

fd853c00e2/compiler/rustc_typeck/src/hir_wf_check.rs (L131-L134)

Therefore, I have changed `check_associated_item()` to pass a `WellFormed(None)` for associated constants.

r? ``@Aaron1011``
2021-07-28 18:28:23 +09:00
Yuki Okushi
23479f716a
Rollup merge of #87501 - spastorino:remove-min-tait, r=oli-obk
Remove min_type_alias_impl_trait in favor of type_alias_impl_trait

r? ``@oli-obk``
2021-07-28 18:28:19 +09:00
Yuki Okushi
954137ea0e
Rollup merge of #87453 - ibraheemdev:i-68697, r=wesleywiser
Suggest removing unnecessary &mut as help message

Closes #68697
2021-07-28 18:28:17 +09:00
bors
eba3228b2a Auto merge of #86251 - Smittyvb:thir-tree-again, r=oli-obk
Support -Z unpretty=thir-tree again

Currently `-Z unpretty=thir-tree` is broken after some THIR refactorings. This re-implements it, making it easier to debug THIR-related issues.

We have to do analyzes before getting the THIR, since trying to create THIR from invalid HIR can ICE. But doing those analyzes requires the THIR to be built and stolen. We work around this by creating a separate query to construct the THIR tree string representation.

Closes https://github.com/rust-lang/project-thir-unsafeck/issues/8, fixes #85552.
2021-07-28 09:01:11 +00:00
bors
aea2e446f0 Auto merge of #86735 - jhpratt:rfc-3107, r=petrochenkov
Implement RFC 3107: `#[derive(Default)]` on enums with a `#[default]` attribute

This PR implements RFC 3107, which permits `#[derive(Default)]` on enums where a unit variant has a `#[default]` attribute. See comments for current status.
2021-07-28 05:59:30 +00:00
bors
8b50cc9a2c Auto merge of #85769 - jhpratt:stabilize-const-transmute-union, r=RalfJung
Stabilize `const_fn_transmute`, `const_fn_union`

This PR stabilizes the `const_fn_transmute` and `const_fn_union` features. It _does not_ stabilize any methods (obviously aside from `transmute`) that are blocked on only these features.

Closes #53605. Closes #51909.
2021-07-28 00:53:17 +00:00
Fabian Wolff
dbd0fd2c2a Fix ICE in diagnostic_hir_wf_check 2021-07-28 01:41:52 +02:00
LeSeulArtichaut
40b57be547 Don't run MIR unsafeck at all when using -Zthir-unsafeck 2021-07-27 23:26:55 +02:00
Jacob Pratt
7bf791d162
Stabilize const_fn_union 2021-07-27 16:03:33 -04:00
Jacob Pratt
36f02f3523
Stabilize const_fn_transmute 2021-07-27 16:03:09 -04:00
bors
2faabf5793 Auto merge of #80367 - camelid:check_match-combine-loop, r=Nadrieril
Combine two loops in `check_match`

Suggested by Nadrieril in
https://github.com/rust-lang/rust/pull/79051#discussion_r548778186.

Opening to get a perf run. Hopefully this code doesn't require everything in the
first loop to be done before running the second! (It shouldn't though.)

cc `@Nadrieril`
2021-07-27 19:56:18 +00:00
Jacob Pratt
72465b0a32
Prohibit #[default] in invalid places 2021-07-27 15:47:49 -04:00
Jacob Pratt
5ae2371ceb
Indicate E0665 is no longer emitted 2021-07-27 15:47:49 -04:00
Jacob Pratt
eef2856eaf
Add machine-applicable suggestions
This avoids the need for tools like rust-analyzer to implement these
suggestions themselves.
2021-07-27 15:47:49 -04:00
Jacob Pratt
c70147fd66
Permit deriving default on enums with #[default] 2021-07-27 15:47:47 -04:00
Aaron Hill
cf167c9c9c
Only emit lint for local macros 2021-07-27 14:18:46 -05:00
Aaron Hill
886dea2bcd
Make SEMICOLON_IN_EXPRESSIONS_FROM_MACROS warn by default 2021-07-27 14:17:37 -05:00
Chris Midgley
bc70252f50 Mark code as ignored due to requiring external plugin 2021-07-27 19:44:50 +01:00
Chris Midgley
7f563f7f4e Add long explanation for E0498 2021-07-27 18:06:34 +01:00
bors
fd853c00e2 Auto merge of #83484 - JulianKnodt:infer, r=oli-obk,lcnr
Add hir::GenericArg::Infer

In order to extend inference to consts, make an Infer type on hir::GenericArg.
2021-07-27 16:24:45 +00:00
Santiago Pastorino
9629d798ca
Remove min_type_alias_impl_trait feature 2021-07-27 12:33:14 -03:00
Santiago Pastorino
66dbeb5f23
existential_type was removed in favor of type_alias_impl_trait 2021-07-27 12:33:13 -03:00
Santiago Pastorino
38bdd0e019
Make all tests use type_alias_impl_trait feature instead of min 2021-07-27 12:33:02 -03:00
Santiago Pastorino
5bff8429a0
Use type_alias_impl_trait instead of min in compiler and lib 2021-07-27 12:27:08 -03:00
Yuki Okushi
54367b90fc
Rollup merge of #87499 - ibraheemdev:patch-6, r=dtolnay
Remove ASCII fast path from `rustc_lexer::{is_id_continue, is_id_start}`

`unicode_xid` now has a fast path built-in: 122b38775c
2021-07-27 19:52:50 +09:00
Yuki Okushi
a981cffb23
Rollup merge of #87497 - midgleyc:long-E0544, r=GuillaumeGomez
Add long explanation for E0544.

Helps with #61137
2021-07-27 19:52:49 +09:00
Yuki Okushi
d25439481c
Rollup merge of #87427 - RalfJung:no-mir-for, r=oli-obk
get rid of NoMirFor error variant

The only place where we throw that error, it is very quickly caught again and turned into a different error. So raise that other error immediately.
2021-07-27 19:52:46 +09:00
Yuki Okushi
4e1ebf23cd
Rollup merge of #86764 - estebank:issue-86756, r=pnkfelix
Avoid ICE on type error recovery

Fix #86756
2021-07-27 19:52:41 +09:00
Yuki Okushi
99a6474bc4
Rollup merge of #86450 - tmiasko:move-size-limit, r=pnkfelix
Add flag to configure `large_assignments` lint

The `large_assignments` lints detects moves over specified limit.  The
limit is configured through `move_size_limit = "N"` attribute placed at
the root of a crate. When attribute is absent, the lint is disabled.

Make it possible to enable the lint without making any changes to the
source code, through a new flag `-Zmove-size-limit=N`.  For example, to
detect moves exceeding 1023 bytes in a cargo crate, including all
dependencies one could use:

```
$ env RUSTFLAGS=-Zmove-size-limit=1024 cargo build -vv
```

Lint tracking issue #83518.
2021-07-27 19:52:40 +09:00
bors
998cfe5aad Auto merge of #85305 - MarcusDunn:master, r=pnkfelix
Stabilize bindings_after_at

attempting to stabilze bindings_after_at [#65490](https://github.com/rust-lang/rust/issues/65490), im pretty new to the whole thing so any pointers are greatly appreciated.
2021-07-27 05:53:31 +00:00
bors
7d6bf861f8 Auto merge of #83491 - jyn514:remove-pretty, r=pnkfelix
Remove unstable `--pretty` flag

It doesn't do anything `--unpretty` doesn't, and due to a bug, also
didn't show up in `--help`. I don't think there's any reason to keep it
around, I haven't seen anyone using it.

Closes https://github.com/rust-lang/rust/issues/36473.
2021-07-27 03:12:40 +00:00
Ibraheem Ahmed
a397fdcc38
Remove ASCII fast path from rustc_lexer::{is_id_continue, is_id_start} 2021-07-26 20:17:28 -04:00
Chris Midgley
b21024f7b9 Add long explanation for E0544. 2021-07-26 22:59:16 +01:00
bors
8bebfe5cc2 Auto merge of #87480 - GuillaumeGomez:rollup-3ly8t5d, r=GuillaumeGomez
Rollup of 8 pull requests

Successful merges:

 - #87436 (Suggest `;` on parse error where applicable)
 - #87444 (Flatten nested `format!` calls)
 - #87447 (Miri: santiy check that null pointer can never have an AllocId)
 - #87457 (freebsd remove compiler workaround.)
 - #87458 (Fix help message for modification to &T created by &{t})
 - #87464 (Remove unnecessary `structhead` parameter from `render_union`)
 - #87473 (Notify the Rust 2021 edition working group in zulip of edition bugs)
 - #87474 (Add missing whitespace after attribute in HTML template)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-07-26 21:50:24 +00:00
kadmin
8759f00c73 Actually infer args in visitors 2021-07-26 21:15:18 +00:00