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

Rustc incorrectly points to where-clause bound when calling static method on invalid type #82038

Closed
Aaron1011 opened this issue Feb 12, 2021 · 0 comments · Fixed by #115649
Closed
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-trait-system Area: Trait system C-bug Category: This is a bug. D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. D-verbose Diagnostics: Too much output caused by a single piece of incorrect code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Aaron1011
Copy link
Member

The following code:

trait Foo {
    fn my_method() where Self: Clone;
}

fn main() {
    <bool as Foo>::my_method();
}

produces the following output:

error[E0277]: the trait bound `bool: Foo` is not satisfied
 --> src/main.rs:6:5
  |
2 |     fn my_method() where Self: Clone;
  |                                ----- required by this bound in `Foo::my_method`
...
6 |     <bool as Foo>::my_method();
  |     ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Foo` is not implemented for `bool`

error: aborting due to previous error

The root cause of the error is the fact that bool does not implement Foo, so the Self: Clone bound isn't relevant. If the where clause is split over multiple lines, then this can obscure the actual cause of the error.

@Aaron1011 Aaron1011 added A-diagnostics Area: Messages for errors, warnings, and lints A-trait-system Area: Trait system C-bug Category: This is a bug. D-verbose Diagnostics: Too much output caused by a single piece of incorrect code. labels Feb 12, 2021
@estebank estebank added 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. labels Feb 14, 2021
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Sep 7, 2023
…ler-errors

diagnostics: add test case for trait bounds diagnostic

Closes rust-lang#82038

It was fixed by rust-lang#89580, a wide-reaching obligation tracking improvement. This commit adds a test case.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Sep 8, 2023
…ler-errors

diagnostics: add test case for trait bounds diagnostic

Closes rust-lang#82038

It was fixed by rust-lang#89580, a wide-reaching obligation tracking improvement. This commit adds a test case.
@bors bors closed this as completed in 31e5dd3 Sep 8, 2023
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Sep 8, 2023
Rollup merge of rust-lang#115649 - notriddle:notriddle/82038, r=compiler-errors

diagnostics: add test case for trait bounds diagnostic

Closes rust-lang#82038

It was fixed by rust-lang#89580, a wide-reaching obligation tracking improvement. This commit adds a test case.
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 A-trait-system Area: Trait system C-bug Category: This is a bug. D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. D-verbose Diagnostics: Too much output caused by a single piece of incorrect code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants