Skip to content

Only a single error is emitted for multiple equal unmet bounds arising from distinct generic parameters on the same item #115288

@fmease

Description

@fmease

Uplifted from #105306 (comment) & #105306 (comment).
CC @estebank

For the following erroneous code, rustc only emits a single error while ideally it should emit two errors. Presumably, this happens because the two predicate obligations for String: Copy have the same cause span (namely of the entire path) before any fulfillment error adjustment takes place and therefore they get deduplicated early on. Details may vary.

Original reproducer (involving projections):

trait Trait {
    type P<T: Copy, U: Copy>;
}
impl Trait for () {
    type P<T: Copy, U: Copy> = ();
}
fn main() {
    let _: <() as Trait>::P<String, String>;
}

Current output (1 error):

error[E0277]: the trait bound `String: Copy` is not satisfied
 --> src/main.rs:8:29
  |
8 |     let _: <() as Trait>::P<String, String>;
  |                             ^^^^^^ the trait `Copy` is not implemented for `String`
  |
note: required by a bound in `Trait::P`
 --> src/main.rs:2:15
  |
2 |     type P<T: Copy, U: Copy>;
  |               ^^^^ required by this bound in `Trait::P`

Expected output (2 errors):

error[E0277]: the trait bound `String: Copy` is not satisfied
 --> src/main.rs:8:12
  |
8 |     let _: <() as Trait>::P<String, String>;
  |                             ^^^^^^ the trait `Copy` is not implemented for `String`
  |
note: required by a bound in `Trait::P`
 --> src/main.rs:2:15
  |
2 |     type P<T: Copy, U: Copy>;
  |               ^^^^ required by this bound in `Trait::P`

error[E0277]: the trait bound `String: Copy` is not satisfied
 --> src/main.rs:8:12
  |
8 |     let _: <() as Trait>::P<String, String>;
  |                                     ^^^^^^ the trait `Copy` is not implemented for `String`
  |
note: required by a bound in `Trait::P`
 --> src/main.rs:2:24
  |
2 |     type P<T: Copy, U: Copy>;
  |                        ^^^^ required by this bound in `Trait::P`

Another very similar reproducer (involving ADTs) which probably takes a slightly different execution path in the compiler:

struct S<T: Copy, U: Copy>(T, U);

fn main() {
    let _: S<String, String>;
}

Meta

rustc -Vv
rustc 1.74.0-nightly (668bf8c59 2023-08-27)
binary: rustc
commit-hash: 668bf8c5932933255ba278f50fdbe308f7abe60f
commit-date: 2023-08-27
host: x86_64-unknown-linux-gnu
release: 1.74.0-nightly
LLVM version: 17.0.0

@rustbot label T-compiler A-diagnostics D-incorrect

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsD-terseDiagnostics: An error or lint that doesn't give enough information about the problem at hand.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions