Commit Graph

7583 Commits

Author SHA1 Message Date
Matthias Krüger ed528515d0
Rollup merge of #120801 - oli-obk:drop_recursion_ice, r=Nilstrieb
Avoid ICE in drop recursion check in case of invalid drop impls

fixes #120787
2024-02-08 20:35:01 +01:00
Matthias Krüger 949e55299d
Rollup merge of #120775 - Nadrieril:more-min_exh_pats, r=compiler-errors
Make `min_exhaustive_patterns` match `exhaustive_patterns` better

Split off from https://github.com/rust-lang/rust/pull/120742.

There remained two edge cases where `min_exhaustive_patterns` wasn't behaving like `exhaustive_patterns`. This fixes them, and tests the feature in a bunch more cases. I essentially went through all uses of `exhaustive_patterns` to see which ones would be interesting to compare between the two features.

r? `@compiler-errors`
2024-02-08 20:34:59 +01:00
Oli Scherer ad511ef92e Avoid ICE in drop recursion check in case of invalid drop impls 2024-02-08 17:33:04 +00:00
bors 1280928a99 Auto merge of #120767 - matthiaskrgr:rollup-0k8ib1c, r=matthiaskrgr
Rollup of 9 pull requests

Successful merges:

 - #119592 (resolve: Unload speculatively resolved crates before freezing cstore)
 - #120103 (Make it so that async-fn-in-trait is compatible with a concrete future in implementation)
 - #120206 (hir: Make sure all `HirId`s have corresponding HIR `Node`s)
 - #120214 (match lowering: consistently lower bindings deepest-first)
 - #120688 (GVN: also turn moves into copies with projections)
 - #120702 (docs: also check the inline stmt during redundant link check)
 - #120727 (exhaustiveness: Prefer "`0..MAX` not covered" to "`_` not covered")
 - #120734 (Add `SubdiagnosticMessageOp` as a trait alias.)
 - #120739 (improve pretty printing for associated items in trait objects)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-02-08 12:14:19 +00:00
Nadrieril 4733b1bba5 Test `min_exhaustive_patterns` in more cases 2024-02-08 11:48:38 +01:00
Oli Scherer eab2adb660 Continue to borrowck even if there were previous errors 2024-02-08 08:10:43 +00:00
Matthias Krüger a059dd88bf
Rollup merge of #120739 - lukas-code:pp-dyn-assoc, r=compiler-errors
improve pretty printing for associated items in trait objects

* Don't print a binder in front of associated items, because it's not valid syntax.
  * e.g. print `dyn for<'a> Trait<'a, Assoc = &'a u8>` instead of `dyn for<'a> Trait<'a, for<'a> Assoc = &'a u8>`.
* Don't print associated items that are implied by a supertrait bound.
  * e.g. if we have `trait Sub: Super<Assoc = u8> {}`, then just print `dyn Sub` instead of `dyn Sub<Assoc = u8>`.

I've added the test in the first commit, so you can see the diff of the compiler output in the second commit.
2024-02-08 09:06:36 +01:00
Matthias Krüger 87e1e05aa1
Rollup merge of #120734 - nnethercote:SubdiagnosticMessageOp, r=compiler-errors
Add `SubdiagnosticMessageOp` as a trait alias.

It avoids a lot of repetition.

r? matthewjasper
2024-02-08 09:06:36 +01:00
Matthias Krüger 5157190008
Rollup merge of #120727 - Nadrieril:tweak-int-reporting, r=compiler-errors
exhaustiveness: Prefer "`0..MAX` not covered" to "`_` not covered"

There was an exception when reporting integer ranges as missing, it's been there for as long as I can remember. This PR removes it. I think it's nicer to report "`0..MAX` not covered" than "`_` not covered". This also makes it consistent with enums, where we report individual enum variants in this case (as showcased in the rest of the `empty-match.rs` test).

r? ``@estebank``
2024-02-08 09:06:35 +01:00
Matthias Krüger fec32358b5
Rollup merge of #120702 - bvanjoi:fix-120444, r=notriddle
docs: also check the inline stmt during redundant link check

Fixes #120444

This issue was brought about by querying `root::webdavfs::A`, a key that doesn't exist in `doc_link_resolutions`. To avoid a panic, I've altered the gating mechanism to allow this lint pass to be skipped.

I'm not certain if this is the best solution. An alternative approach might be to leverage other info from the name resolutions instead of `doc_link_resolutions`. After all, all we need is to get the resolution from a combination of `(module, name)`. However, I believe they would yield the same outcome, both skipping this lint.
2024-02-08 09:06:35 +01:00
Matthias Krüger 65aa9eae73
Rollup merge of #120688 - cjgillot:gvn-partial-move, r=oli-obk
GVN: also turn moves into copies with projections

Fixes https://github.com/rust-lang/rust/issues/120613
2024-02-08 09:06:34 +01:00
Matthias Krüger 7fb36f2d3b
Rollup merge of #120214 - Nadrieril:fix-120210, r=pnkfelix
match lowering: consistently lower bindings deepest-first

Currently when lowering match expressions to MIR, we do a funny little dance with the order of bindings. I attempt to explain it in the third commit: we handle refutable (i.e. needing a test) patterns differently than irrefutable ones. This leads to inconsistencies, as reported in https://github.com/rust-lang/rust/issues/120210. The reason we need a dance at all is for situations like:

```rust
fn foo1(x: NonCopyStruct) {
    let y @ NonCopyStruct { copy_field: z } = x;
    // the above should turn into
    let z = x.copy_field;
    let y = x;
}
```

Here the `y ```````@```````` binding will move out of `x`, so we need to copy the field first.

I believe that the inconsistency came about when we fixed https://github.com/rust-lang/rust/issues/69971, and didn't notice that the fix didn't extend to refutable patterns. My guess then is that ordering bindings by "deepest-first, otherwise source order" is a sound choice. This PR implements that (at least I hope, match lowering is hard to follow 🥲).

Fixes https://github.com/rust-lang/rust/issues/120210

r? ```````@oli-obk``````` since you merged the original fix to https://github.com/rust-lang/rust/issues/69971
cc ```````@matthewjasper```````
2024-02-08 09:06:33 +01:00
Matthias Krüger 9ec5960e3d
Rollup merge of #120103 - compiler-errors:concrete-afits, r=oli-obk
Make it so that async-fn-in-trait is compatible with a concrete future in implementation

There's no technical reason why an AFIT like `async fn foo()` cannot be satisfied with an implementation signature like `fn foo() -> Pin<Box<dyn Future<Output = ()> + 'static>>`.

We rejected this previously because we were uncertain about how AFITs worked with refinement, but I don't believe this needs to be a restriction any longer.

r? oli-obk
2024-02-08 09:06:32 +01:00
Matthias Krüger 4e11d03d0e
Rollup merge of #119592 - petrochenkov:unload, r=compiler-errors
resolve: Unload speculatively resolved crates before freezing cstore

Name resolution sometimes loads additional crates to improve diagnostics (e.g. suggest imports).
Not all of these diagnostics result in errors, sometimes they are just warnings, like in #117772.

If additional crates loaded speculatively stay and gets listed by things like `query crates` then they may produce further errors like duplicated lang items, because lang items from speculatively loaded crates are as good as from non-speculatively loaded crates.
They can probably do things like adding unintended impls from speculatively loaded crates to method resolution as well.
The extra crates will also get into the crate's metadata as legitimate dependencies.

In this PR I remove the speculative crates from cstore when name resolution is finished and cstore is frozen.
This is better than e.g. filtering away speculative crates in `query crates` because things like `DefId`s referring to these crates and leaking to later compilation stages can produce ICEs much easier, allowing to detect them.

The unloading could potentially be skipped if any errors were reported (to allow using `DefId`s from speculatively loaded crates for recovery), but I didn't do it in this PR because I haven't seen such cases of recovery. We can reconsider later if any relevant ICEs are reported.

Unblocks https://github.com/rust-lang/rust/pull/117772.
2024-02-08 09:06:31 +01:00
Oli Scherer e5461de392 Taint borrowck results without running any borrowck if the MIR body was already tainted 2024-02-08 07:39:49 +00:00
Oli Scherer 8a5847f5c4 Already poison the `type_of` result of the anon const used in the `typeof` expression 2024-02-08 07:32:30 +00:00
bors 870a01a30e Auto merge of #120558 - oli-obk:missing_impl_item_ice, r=estebank
Stop bailing out from compilation just because there were incoherent traits

fixes #120343

but also has a lot of "type annotations needed" fallout. Some are fixed in the second commit.
2024-02-08 05:01:09 +00:00
bors 384b02c082 Auto merge of #120521 - reitermarkus:generic-nonzero-constructors, r=dtolnay
Make `NonZero` constructors generic.

This makes `NonZero` constructors generic, so that `NonZero::new` can be used without turbofish syntax.

Tracking issue: https://github.com/rust-lang/rust/issues/120257

~~I cannot figure out how to make this work with `const` traits. Not sure if I'm using it wrong or whether there's a bug:~~

```rust
101 |         if n == T::ZERO {
    |            ^^^^^^^^^^^^ expected `host`, found `true`
    |
    = note: expected constant `host`
               found constant `true`
```

r? `@dtolnay`
2024-02-08 03:00:34 +00:00
Nicholas Nethercote 6b175a848d Add `SubdiagnosticMessageOp` as a trait alias.
It avoids a lot of repetition.
2024-02-08 13:02:44 +11:00
bors 6894f435d3 Auto merge of #120381 - fee1-dead-contrib:reconstify-add, r=compiler-errors
Reconstify `Add`

r? project-const-traits

I'm not happy with the ui test changes (or failures because I did not bless them and include the diffs in this PR). There is at least some bugs I need to look and try fix:

1. A third duplicated diagnostic when a consumer crate that does not have `effects` enabled has a trait selection error for an upstream const_trait trait. See tests/ui/ufcs/ufcs-qpath-self-mismatch.rs.
2. For some reason, making `Add` a const trait would stop us from suggesting `T: Add` when we try to add two `T`s without that bound. See tests/ui/suggestions/issue-97677.rs
2024-02-08 00:04:14 +00:00
Nadrieril 9dca6be7b8 Prefer "0..MAX not covered" to "_ not covered" 2024-02-07 23:25:11 +01:00
Nadrieril 970f46c60d Add tests 2024-02-07 23:22:46 +01:00
Lukas Markeffsky c636c7ae2c address review comments and add more tests 2024-02-07 20:58:05 +01:00
Guillaume Boisseau b715d9303e
Rollup merge of #120746 - compiler-errors:kind-ty, r=oli-obk
Record coroutine kind in coroutine generics

Oops, added a new substitution (the "kind" ty) to coroutines but forgot to record it in the `generics_of`. I'm surprised I left this out of the coroutine-closure PR -- I thought I made this change; I possibly rebased it out by accident.

Fixes #120732

r? oli-obk
2024-02-07 18:24:46 +01:00
Guillaume Boisseau eecab310fe
Rollup merge of #120664 - SparrowLii:parallel_test, r=nnethercote
Add parallel rustc ui tests

Updates #118698

Add some ui tests for parallel rustc front end

This is a relatively large feature so I think it's worth creating a new entity in tests/ui folder, so we need to modify the limit in tidy.
2024-02-07 18:24:44 +01:00
Guillaume Boisseau cc7edbc1e4
Rollup merge of #120479 - estebank:issue-61788, r=wesleywiser
Suggest turning `if let` into irrefutable `let` if appropriate

When encountering an `if let` tail expression without an `else` arm for an enum with a single variant, suggest writing an irrefutable `let` binding instead.

```
error[E0317]: `if` may be missing an `else` clause
  --> $DIR/irrefutable-if-let-without-else.rs:8:5
   |
LL |   fn foo(x: Enum) -> i32 {
   |                      --- expected `i32` because of this return type
LL | /     if let Enum::Variant(value) = x {
LL | |         value
LL | |     }
   | |_____^ expected `i32`, found `()`
   |
   = note: `if` expressions without `else` evaluate to `()`
   = help: consider adding an `else` block that evaluates to the expected type
help: consider using an irrefutable `let` binding instead
   |
LL ~     let Enum::Variant(value) = x;
LL ~         value
   |
```

Fix #61788.
2024-02-07 18:24:43 +01:00
Guillaume Boisseau f5a36cbd73
Rollup merge of #120470 - estebank:issue-54196, r=compiler-errors
Mark "unused binding" suggestion as maybe incorrect

Ignoring unused bindings should be a determination made by a human, `rustfix` shouldn't auto-apply the suggested change.

Fix #54196.
2024-02-07 18:24:42 +01:00
Guillaume Boisseau 65c09546ac
Rollup merge of #120455 - JarlEvanson:sroa-miri-tests, r=cjgillot
Add FileCheck annotations to MIR-opt SROA tests

Part of #116971, adds FileCheck annotations to SROA MIR-opt tests in `tests/mir-opt/sroa` and a few uncategorized files.

r? cjgillot
2024-02-07 18:24:42 +01:00
Guillaume Boisseau 7954c28cf9
Rollup merge of #119162 - heiher:direct-access-external-data, r=petrochenkov
Add unstable `-Z direct-access-external-data` cmdline flag for `rustc`

The new flag has been described in the Major Change Proposal at https://github.com/rust-lang/compiler-team/issues/707

Fixes #118053
2024-02-07 18:24:41 +01:00
Guillaume Boisseau 6931780f40
Rollup merge of #110482 - chrisnc:armv8r-target, r=wesleywiser
Add armv8r-none-eabihf target for the Cortex-R52.
2024-02-07 18:24:41 +01:00
Michael Goulet dcca9a12cd Record coroutine kind in generics 2024-02-07 16:18:31 +00:00
Lukas Markeffsky 18e5bbfad6 improve pretty printing for trait objects 2024-02-07 16:09:46 +01:00
Markus Reiter 42298756c7
Update test output. 2024-02-07 16:01:58 +01:00
bors d6c46a23ce Auto merge of #120060 - saethlin:mir-opt-bless-targets, r=wesleywiser
Use the same mir-opt bless targets on all platforms

This undoes some of the implementation in https://github.com/rust-lang/rust/pull/119035, but not the effect. Sorry for the churn, I've learned a lot about how all this works over the past few weeks.

The objective here is to make `x test mir-opt --bless` use the same set of targets on all platforms. It didn't do that from the start because bootstrap assumes that a target linker is available, so the availability of cross-linkers is how we ended up with `MIR_OPT_BLESS_TARGET_MAPPING` and poor support for blessing mir-opt tests from Aarch64 MacOS. This PR corrects that.

So I've adjusted the bless targets for mir-opt tests, as well as tweaked some of the logic in bootstrap about linker configuration so that we don't try to access the cache of cc/linker configuration when doing the mir-opt builds.

While working on that I realized that if I swapped from the `cargo rustc -p std` strategy to `cargo check` on the sysroot, I could use the existing code for check builds to bypass some linker logic. Sweet.

But just doing that doesn't work, because then mir-opt tests complain that they can't find an rlib for any of the standard library crates. That happens because nearly all the mir-opt tests are attempting to build `CrateType::Executable`. We already have all the MIR required for mir-opt tests from the rmeta files, but since rustc think we're trying to build an executable it demands we have access to all the upstream monomorphizations that only exist in rlibs, not the meta files in a MIR-only sysroot.

So to fix that, I've swapped all the mir-opt tests be passed `--crate-type=rlib`. That works, but leaves us with a few broken mir-opt tests which I've blessed or fixed up; we also lose MIR for some functions so I added `-Clink-dead-code` to paper over that. The inlining changes are because changing the crate-type perturbs the hashes that are compared here to sometimes let us do inlining even in a possibly-recursive call: 4cb17b4e78/compiler/rustc_mir_transform/src/inline.rs (L332-L341)
2024-02-07 14:01:21 +00:00
Lukas Markeffsky fd9202109b add test for pretty printing trait objects 2024-02-07 12:51:31 +01:00
bohan 0a50dba50b docs: also check the inline stmt during redundant link check 2024-02-07 15:43:32 +08:00
SparrowLii a59d00674a Add parallel rustc ui tests 2024-02-07 15:26:57 +08:00
Ben Kimock 3c7a8b9d71 Fixup async_closure_shims mir-opt test 2024-02-06 23:40:58 -05:00
Ben Kimock 2116ed723d Tweak a few mir-opt tests instead of using -Clink-dead-code 2024-02-06 23:36:05 -05:00
Ben Kimock 4451bf4d67 Use a better set of targets for blessing mir-opt tests 2024-02-06 23:36:05 -05:00
r0cky c7519d42c2 Update tests 2024-02-07 10:42:01 +08:00
r0cky 40878ca6ea Make traits / trait methods detected by the dead code lint! 2024-02-07 10:22:16 +08:00
bors 586893c7b0 Auto merge of #120722 - matthiaskrgr:rollup-9o32280, r=matthiaskrgr
Rollup of 9 pull requests

Successful merges:

 - #119939 (Improve 'generic param from outer item' error for `Self` and inside `static`/`const` items)
 - #120331 (pattern_analysis: use a plain `Vec` in `DeconstructedPat`)
 - #120396 (Account for unbounded type param receiver in suggestions)
 - #120423 (update indirect structural match lints to match RFC and to show up for dependencies)
 - #120435 (Suggest name value cfg when only value is used for check-cfg)
 - #120502 (Remove `ffi_returns_twice` feature)
 - #120507 (Account for non-overlapping unmet trait bounds in suggestion)
 - #120513 (Normalize type outlives obligations in NLL for new solver)
 - #120707 (Don't expect early-bound region to be local when reporting errors in RPITIT well-formedness)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-02-07 00:03:50 +00:00
Matthias Krüger 84114fea9e
Rollup merge of #120707 - compiler-errors:suitable-region, r=nnethercote
Don't expect early-bound region to be local when reporting errors in RPITIT well-formedness

The implicit lifetime in the example code gets replaced with `ReError`, which fails a `sub_regions` check in the lexical region solver. Error reporting ends up calling `is_suitable_region` on an early bound region in the *trait* definition. This causes an ICE because we `expect_local()`.

This is kind of a bad explanation, but this code just makes diagnostics reporting a bit more gracefully fallible. If the reviewer wants a thorough investigation of exactly where we get this region outlives obligation, I can write one up. Doesn't really seem worth it, though, imo.

Fixes #120638
Fixes #120648
2024-02-06 22:45:43 +01:00
Matthias Krüger 012ce8ae98
Rollup merge of #120513 - compiler-errors:normalize-regions-for-nll, r=lcnr
Normalize type outlives obligations in NLL for new solver

Normalize the type outlives assumptions and obligations in MIR borrowck. This should fix any of the lazy-norm-related MIR borrowck problems.

Also some cleanups from last PR:
1. Normalize obligations in a loop in lexical region resolution
2. Use `deeply_normalize_with_skipped_universes` in lexical resolution since we may have, e.g. `for<'a> Alias<'a>: 'b`.

r? lcnr
2024-02-06 22:45:43 +01:00
Matthias Krüger af99946700
Rollup merge of #120507 - estebank:issue-108428, r=davidtwco
Account for non-overlapping unmet trait bounds in suggestion

When a method not found on a type parameter could have been provided by any
of multiple traits, suggest each trait individually, instead of a single
suggestion to restrict the type parameter with *all* of them.

Before:

```
error[E0599]: the method `cmp` exists for reference `&T`, but its trait bounds were not satisfied
  --> $DIR/method-on-unbounded-type-param.rs:5:10
   |
LL |     (&a).cmp(&b)
   |          ^^^ method cannot be called on `&T` due to unsatisfied trait bounds
   |
   = note: the following trait bounds were not satisfied:
           `T: Ord`
           which is required by `&T: Ord`
           `&T: Iterator`
           which is required by `&mut &T: Iterator`
           `T: Iterator`
           which is required by `&mut T: Iterator`
help: consider restricting the type parameters to satisfy the trait bounds
   |
LL | fn g<T>(a: T, b: T) -> std::cmp::Ordering where T: Iterator, T: Ord {
   |                                           +++++++++++++++++++++++++
```

After:

```
error[E0599]: the method `cmp` exists for reference `&T`, but its trait bounds were not satisfied
  --> $DIR/method-on-unbounded-type-param.rs:5:10
   |
LL |     (&a).cmp(&b)
   |          ^^^ method cannot be called on `&T` due to unsatisfied trait bounds
   |
   = note: the following trait bounds were not satisfied:
           `T: Ord`
           which is required by `&T: Ord`
           `&T: Iterator`
           which is required by `&mut &T: Iterator`
           `T: Iterator`
           which is required by `&mut T: Iterator`
   = help: items from traits can only be used if the type parameter is bounded by the trait
help: the following traits define an item `cmp`, perhaps you need to restrict type parameter `T` with one of them:
   |
LL | fn g<T: Ord>(a: T, b: T) -> std::cmp::Ordering {
   |       +++++
LL | fn g<T: Iterator>(a: T, b: T) -> std::cmp::Ordering {
   |       ++++++++++
```

Fix #108428.

Follow up to #120396, only last commit is relevant.
2024-02-06 22:45:42 +01:00
Matthias Krüger 59ba8024af
Rollup merge of #120502 - clubby789:remove-ffi-returns-twice, r=compiler-errors
Remove `ffi_returns_twice` feature

The [tracking issue](https://github.com/rust-lang/rust/issues/58314) and [RFC](https://github.com/rust-lang/rfcs/pull/2633) have been closed for a couple of years.

There is also an attribute gate in R-A which should be removed if this lands.
2024-02-06 22:45:42 +01:00
Matthias Krüger 0a4702d011
Rollup merge of #120435 - chenyukang:yukang-fix-120427-cfg-name, r=Urgau,Nilstrieb
Suggest name value cfg when only value is used for check-cfg

Fixes #120427
r? `````````````@Nilstrieb`````````````
2024-02-06 22:45:41 +01:00
Matthias Krüger 176c4ba5c3
Rollup merge of #120423 - RalfJung:indirect-structural-match, r=petrochenkov
update indirect structural match lints to match RFC and to show up for dependencies

This is a large step towards implementing https://github.com/rust-lang/rfcs/pull/3535.
We currently have five lints related to "the structural match situation":
- nontrivial_structural_match
- indirect_structural_match
- pointer_structural_match
- const_patterns_without_partial_eq
- illegal_floating_point_literal_pattern

This PR concerns the first 3 of them. (The 4th already is set up to show for dependencies, and the 5th is removed by https://github.com/rust-lang/rust/pull/116284.) nontrivial_structural_match is being removed as per the RFC; the other two are enabled to show up in dependencies.

Fixes https://github.com/rust-lang/rust/issues/73448 by removing the affected analysis.
2024-02-06 22:45:41 +01:00
Matthias Krüger a0c3b87823
Rollup merge of #120396 - estebank:method-on-unbounded-type-param, r=nnethercote
Account for unbounded type param receiver in suggestions

When encountering

```rust
fn f<T>(a: T, b: T) -> std::cmp::Ordering {
    a.cmp(&b) //~ ERROR E0599
}
```

output

```
error[E0599]: no method named `cmp` found for type parameter `T` in the current scope
  --> $DIR/method-on-unbounded-type-param.rs:2:7
   |
LL | fn f<T>(a: T, b: T) -> std::cmp::Ordering {
   |      - method `cmp` not found for this type parameter
LL |     a.cmp(&b)
   |       ^^^ method cannot be called on `T` due to unsatisfied trait bounds
   |
   = help: items from traits can only be used if the type parameter is bounded by the trait
help: the following traits define an item `cmp`, perhaps you need to restrict type parameter `T` with one of them:
   |
LL | fn f<T: Ord>(a: T, b: T) -> std::cmp::Ordering {
   |       +++++
LL | fn f<T: Iterator>(a: T, b: T) -> std::cmp::Ordering {
   |       ++++++++++
```

Fix #120186.
2024-02-06 22:45:40 +01:00