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

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

Open
fmease opened this issue Aug 27, 2023 · 0 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints D-terse Diagnostics: An error or lint that doesn't give enough information about the problem at hand. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@fmease
Copy link
Member

fmease commented Aug 27, 2023

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

@rustbot rustbot added needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug. D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. C-bug Category: This is a bug. labels Aug 27, 2023
@fmease fmease changed the title Only a single error is emitted for multiple equal unmet bounds arising from distinct type parameters on the same item Only a single error is emitted for multiple equal unmet bounds arising from distinct generic parameters on the same item Aug 27, 2023
@estebank estebank added D-terse Diagnostics: An error or lint that doesn't give enough information about the problem at hand. and removed D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. labels Dec 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints D-terse Diagnostics: An error or lint that doesn't give enough information about the problem at hand. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants