Skip to content

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

Closed
@Aaron1011

Description

@Aaron1011

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-trait-systemArea: Trait systemC-bugCategory: This is a bug.D-incorrectDiagnostics: A diagnostic that is giving misleading or incorrect information.D-verboseDiagnostics: Too much output caused by a single piece of incorrect code.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