Skip to content

E0277 message is misleading when there's a blanket impl #40120

Closed
@aldanor

Description

@aldanor
trait Foo { fn foo() {} }
trait Bar {}
impl<T: Bar> Foo for T {}

fn main() {
    <i32 as Foo>::foo();
}

Reported error tries to be too smart:

error[E0277]: the trait bound `i32: Bar` is not satisfied
  |
  |     <i32 as Foo>::foo();
  |     ^^^^^^^^^^^^^^^^^ the trait `Bar` is not implemented for `i32`
  |
  = note: required because of the requirements on the impl of `Foo` for `i32`
  = note: required by `Foo::foo`

... but is misleading since the real error is that i32: Foo is not satisfied; i32 may happen to implement Foo and not implement Bar, so the error message is actually just wrong.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-trait-systemArea: Trait systemC-enhancementCategory: An issue proposing an enhancement or a PR with one.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