Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 9 pull requests #120662

Closed
wants to merge 34 commits into from

Conversation

matthiaskrgr
Copy link
Member

Successful merges:

r? @ghost
@rustbot modify labels: rollup

Create a similar rollup

RalfJung and others added 30 commits January 27, 2024 13:50
Co-authored-by: Urgau <3616612+Urgau@users.noreply.github.com>
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 rust-lang#120186.
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 rust-lang#108428.
It doesn't affect behaviour, but makes sense with (a) `FailureNote` having
`()` as its emission guarantee, and (b) in `Level` the `is_error` levels
now are all listed before the non-`is_error` levels.
I.e. `Bug` and `Fatal` level diagnostics are never downgraded.
- Combine two different blocks involving
  `diagnostic.level.get_expectation_id()` into one.
- Combine several `if`s involving `diagnostic.level` into a single
  `match`.

This requires reordering some of the operations, but this has no
functional effect.
The two kinds of delayed bug have quite different semantics so a
stronger conceptual separation is nice. (`is_error` is a good example,
because the two kinds have different behaviour.)

The commit also moves the `DelayedBug` variant after `Error` in `Level`,
to reflect the fact that it's weaker than `Error` -- it might trigger an
error but also might not. (The pre-existing `downgrade_to_delayed_bug`
function also reflects the notion that delayed bugs are lower/after
normal errors.)

Plus it condenses some of the comments on `Level` into a table, for
easier reading, and introduces `can_be_top_or_sub` to indicate which
levels can be used in top-level diagnostics vs. subdiagnostics.

Finally, it renames `DiagCtxtInner::span_delayed_bugs` as
`DiagCtxtInner::delayed_bugs`. The `span_` prefix is unnecessary because
some delayed bugs don't have a span.
To send a diagnostic from a codegen thread to the main thread,
`SharedEmitter` currently converts the `rustc_errors::Diagnostic` into a
one or more `rustc_codegen_ssa::Diagnostic`s, sends them, and then
`SharedEmitterMain` reconstructs them at the other end into a
`rustc_errors::Diagnostic`. This is a lossy operation, because of
differences between the two `Diagnostic` types.

Instead we can just clone the `rustc_errors::Diagnostic` and send it
directly. Maybe in the past `rustc_errors::Diagnostic` wasn't `Send`?
But it works now. Much simpler and nicer.
It's now always paired with a `SharedEmitterMessage::Diagnostic`, so the
two message kinds can be combined.
All the other `emit`/`emit_diagnostic` methods were recently made
consuming (e.g. rust-lang#119606), but this one wasn't. But it makes sense to.

Much of this is straightforward, and lots of `clone` calls are avoided.
There are a couple of tricky bits.
- `Emitter::primary_span_formatted` no longer takes a `Diagnostic` and
  returns a pair. Instead it takes the two fields from `Diagnostic` that
  it used (`span` and `suggestions`) as `&mut`, and modifies them. This
  is necessary to avoid the cloning of `diag.children` in two emitters.
- `from_errors_diagnostic` is rearranged so various uses of `diag` occur
  before the consuming `emit_diagnostic` call.
…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 rust-lang#120186.
…, r=petrochenkov

update indirect structural match lints to match RFC and to show up for dependencies

This is a large step towards implementing rust-lang/rfcs#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 rust-lang#116284.) nontrivial_structural_match is being removed as per the RFC; the other two are enabled to show up in dependencies.

Fixes rust-lang#73448 by removing the affected analysis.
…ame, r=Urgau,Nilstrieb

Suggest name value cfg when only value is used for check-cfg

Fixes rust-lang#120427
r? ``````@Nilstrieb``````
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 rust-lang#108428.

Follow up to rust-lang#120396, only last commit is relevant.
…i-obk

Some cleanups around diagnostic levels.

Plus some refactoring in and around diagnostic levels and emission. Details in the individual commit logs.

r? `@oli-obk`
…ructors, r=dtolnay,oli-obk

Make `NonZero` constructors generic.

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

Tracking issue: rust-lang#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```
…ochenkov

Switch OwnedStore handle count to AtomicU32

This is already panics if overflowing a u32, so let's use the smaller int size to save a tiny bit of memory.
Continue to borrowck even if there were previous errors

but only from the perspective of the whole compiler. Individual items should not get borrowcked if their MIR is tainted by errors.

r? ```@estebank``` ```@nnethercote```
…handling, r=estebank

Simplify codegen diagnostic handling

Some nice improvements. Details in the individual commit logs.

r? `@estebank`
@rustbot rustbot added A-translation Area: Translation infrastructure, and migrating existing diagnostics to SessionDiagnostic S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. rollup A PR which is a rollup labels Feb 5, 2024
@matthiaskrgr
Copy link
Member Author

@bors r+ rollup=never p=9

@bors
Copy link
Contributor

bors commented Feb 5, 2024

📌 Commit c28b4a0 has been approved by matthiaskrgr

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 5, 2024
@bors
Copy link
Contributor

bors commented Feb 5, 2024

⌛ Testing commit c28b4a0 with merge 9bf3bbe...

bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 5, 2024
…iaskrgr

Rollup of 9 pull requests

Successful merges:

 - rust-lang#120396 (Account for unbounded type param receiver in suggestions)
 - rust-lang#120423 (update indirect structural match lints to match RFC and to show up for dependencies)
 - rust-lang#120435 (Suggest name value cfg when only value is used for check-cfg)
 - rust-lang#120507 (Account for non-overlapping unmet trait bounds in suggestion)
 - rust-lang#120520 (Some cleanups around diagnostic levels.)
 - rust-lang#120521 (Make `NonZero` constructors generic.)
 - rust-lang#120527 (Switch OwnedStore handle count to AtomicU32)
 - rust-lang#120550 (Continue to borrowck even if there were previous errors)
 - rust-lang#120575 (Simplify codegen diagnostic handling)

r? `@ghost`
`@rustbot` modify labels: rollup
@rust-log-analyzer
Copy link
Collaborator

The job dist-x86_64-linux-alt failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
   Compiling rustc_monomorphize v0.0.0 (/checkout/compiler/rustc_monomorphize)
   Compiling rustc_smir v0.0.0 (/checkout/compiler/rustc_smir)
[RUSTC-TIMING] rustc_target test:false 26.298
   Compiling rustc_codegen_ssa v0.0.0 (/checkout/compiler/rustc_codegen_ssa)
error[E0277]: the trait bound `rustc_span::Span: std::marker::Send` is not satisfied in `SharedEmitterMessage`
    --> compiler/rustc_codegen_ssa/src/back/write.rs:1257:78
     |
1257 |       return B::spawn_named_thread(cgcx.time_trace, "coordinator".to_string(), move || {
     |  ____________---------------------_____________________________________________^
     | |            required by a bound introduced by this call
1258 | |         let mut worker_id_counter = 0;
1258 | |         let mut worker_id_counter = 0;
1259 | |         let mut free_worker_ids = Vec::new();
1260 | |         let mut get_worker_id = |free_worker_ids: &mut Vec<usize>| {
1618 | |         })
1619 | |     })
1619 | |     })
     | |_____^ within `SharedEmitterMessage`, the trait `std::marker::Send` is not implemented for `rustc_span::Span`
note: required because it appears within the type `Diagnostic`
    --> /rustc/9bf3bbef88ce84ba0e2cdd4562bbe50b85b65c23/compiler/rustc_errors/src/diagnostic.rs:97:12
     |
97   | pub struct Diagnostic {
97   | pub struct Diagnostic {
     |            ^^^^^^^^^^
note: required because it appears within the type `SharedEmitterMessage`
    --> compiler/rustc_codegen_ssa/src/back/write.rs:1754:6
     |
1754 | enum SharedEmitterMessage {
     |      ^^^^^^^^^^^^^^^^^^^^
     = note: required for `Sender<SharedEmitterMessage>` to implement `std::marker::Send`
note: required because it appears within the type `SharedEmitter`
    --> compiler/rustc_codegen_ssa/src/back/write.rs:1761:12
1761 | pub struct SharedEmitter {
     |            ^^^^^^^^^^^^^
note: required because it's used within this closure
    --> compiler/rustc_codegen_ssa/src/back/write.rs:1257:78
    --> compiler/rustc_codegen_ssa/src/back/write.rs:1257:78
     |
1257 |     return B::spawn_named_thread(cgcx.time_trace, "coordinator".to_string(), move || {
     |                                                                              ^^^^^^^
note: required by a bound in `backend::ExtraBackendMethods::spawn_named_thread`
     |
     |
140  |     fn spawn_named_thread<F, T>(
...
147  |         F: Send + 'static,
147  |         F: Send + 'static,
     |            ^^^^ required by this bound in `ExtraBackendMethods::spawn_named_thread`

error[E0277]: the trait bound `rustc_span::Span: std::marker::Send` is not satisfied in `SharedEmitterMessage`
    --> compiler/rustc_codegen_ssa/src/back/write.rs:1696:70
     |
1696 |       B::spawn_named_thread(cgcx.time_trace, work.short_description(), move || {
     |  _____---------------------____________________________________________^
     | |     required by a bound introduced by this call
     | |     required by a bound introduced by this call
1697 | |         // Set up a destructor which will fire off a message that we're done as
1698 | |         // we exit.
1699 | |         struct Bomb<B: ExtraBackendMethods> {
1749 | |         };
1750 | |     })
1750 | |     })
     | |_____^ within `SharedEmitterMessage`, the trait `std::marker::Send` is not implemented for `rustc_span::Span`
note: required because it appears within the type `Diagnostic`
    --> /rustc/9bf3bbef88ce84ba0e2cdd4562bbe50b85b65c23/compiler/rustc_errors/src/diagnostic.rs:97:12
     |
97   | pub struct Diagnostic {
97   | pub struct Diagnostic {
     |            ^^^^^^^^^^
note: required because it appears within the type `SharedEmitterMessage`
    --> compiler/rustc_codegen_ssa/src/back/write.rs:1754:6
     |
1754 | enum SharedEmitterMessage {
     |      ^^^^^^^^^^^^^^^^^^^^
     = note: required for `Sender<SharedEmitterMessage>` to implement `std::marker::Send`
note: required because it appears within the type `SharedEmitter`
    --> compiler/rustc_codegen_ssa/src/back/write.rs:1761:12
1761 | pub struct SharedEmitter {
     |            ^^^^^^^^^^^^^
note: required because it appears within the type `CodegenContext<B>`
    --> compiler/rustc_codegen_ssa/src/back/write.rs:328:12
    --> compiler/rustc_codegen_ssa/src/back/write.rs:328:12
     |
328  | pub struct CodegenContext<B: WriteBackendMethods> {
note: required because it's used within this closure
    --> compiler/rustc_codegen_ssa/src/back/write.rs:1696:70
     |
     |
1696 |     B::spawn_named_thread(cgcx.time_trace, work.short_description(), move || {
     |                                                                      ^^^^^^^
note: required by a bound in `backend::ExtraBackendMethods::spawn_named_thread`
     |
     |
140  |     fn spawn_named_thread<F, T>(
...
147  |         F: Send + 'static,
147  |         F: Send + 'static,
     |            ^^^^ required by this bound in `ExtraBackendMethods::spawn_named_thread`
For more information about this error, try `rustc --explain E0277`.
[RUSTC-TIMING] rustc_codegen_ssa test:false 1.816
error: could not compile `rustc_codegen_ssa` (lib) due to 2 previous errors
warning: build failed, waiting for other jobs to finish...
---
Caused by:
    Command RUST_BACKTRACE=full python3 /checkout/x.py build --target x86_64-unknown-linux-gnu --host x86_64-unknown-linux-gnu --stage 2 library/std --rust-profile-generate /tmp/tmp-multistage/opt-artifacts/rustc-pgo --set llvm.thin-lto=false --set llvm.link-shared=true [at /checkout/obj] has failed with exit code Some(1)

Stack backtrace:
   0: <opt_dist::exec::CmdBuilder>::run
             at /rustc/9bf3bbef88ce84ba0e2cdd4562bbe50b85b65c23/src/tools/opt-dist/src/exec.rs:78:17
   1: <opt_dist::exec::Bootstrap>::run
             at /rustc/9bf3bbef88ce84ba0e2cdd4562bbe50b85b65c23/src/tools/opt-dist/src/exec.rs:179:9
   2: opt_dist::execute_pipeline::{closure#1}::{closure#0}
             at /rustc/9bf3bbef88ce84ba0e2cdd4562bbe50b85b65c23/src/tools/opt-dist/src/main.rs:210:13
      <opt_dist::timer::TimerSection>::section::<opt_dist::execute_pipeline::{closure#1}::{closure#0}, ()>
             at /rustc/9bf3bbef88ce84ba0e2cdd4562bbe50b85b65c23/src/tools/opt-dist/src/timer.rs:111:22
      opt_dist::execute_pipeline::{closure#1}
             at /rustc/9bf3bbef88ce84ba0e2cdd4562bbe50b85b65c23/src/tools/opt-dist/src/main.rs:199:9
      <opt_dist::timer::TimerSection>::section::<opt_dist::execute_pipeline::{closure#1}, opt_dist::training::RustcPGOProfile>
             at /rustc/9bf3bbef88ce84ba0e2cdd4562bbe50b85b65c23/src/tools/opt-dist/src/timer.rs:111:22
      opt_dist::execute_pipeline
             at /rustc/9bf3bbef88ce84ba0e2cdd4562bbe50b85b65c23/src/tools/opt-dist/src/main.rs:196:29
             at /rustc/9bf3bbef88ce84ba0e2cdd4562bbe50b85b65c23/src/tools/opt-dist/src/main.rs:385:18
   4: <fn() -> core::result::Result<(), anyhow::Error> as core::ops::function::FnOnce<()>>::call_once
             at /rustc/0e09125c6c3c2fd70d7de961bcf0e51575235fad/library/core/src/ops/function.rs:250:5
             at /rustc/0e09125c6c3c2fd70d7de961bcf0e51575235fad/library/core/src/ops/function.rs:250:5
      std::sys_common::backtrace::__rust_begin_short_backtrace::<fn() -> core::result::Result<(), anyhow::Error>, core::result::Result<(), anyhow::Error>>
   5: std::rt::lang_start::<core::result::Result<(), anyhow::Error>>::{closure#0}
             at /rustc/0e09125c6c3c2fd70d7de961bcf0e51575235fad/library/std/src/rt.rs:166:18
             at /rustc/0e09125c6c3c2fd70d7de961bcf0e51575235fad/library/std/src/rt.rs:166:18
   6: core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &F>::call_once
      std::panicking::try::do_call
             at /rustc/0e09125c6c3c2fd70d7de961bcf0e51575235fad/library/std/src/panicking.rs:552:40
      std::panicking::try
             at /rustc/0e09125c6c3c2fd70d7de961bcf0e51575235fad/library/std/src/panicking.rs:516:19

@bors
Copy link
Contributor

bors commented Feb 5, 2024

💔 Test failed - checks-actions

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Feb 5, 2024
@matthiaskrgr matthiaskrgr deleted the rollup-dbrpeqj branch March 16, 2024 18:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-translation Area: Translation infrastructure, and migrating existing diagnostics to SessionDiagnostic rollup A PR which is a rollup S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.