Skip to content

Misleading error message when there is a generic trait impl for all types implementing other trait #32704

@VFLashM

Description

@VFLashM

See example.
Error message mentions trait 'Base', even thought only 'Marker' trait is required.

trait Base {}
trait Marker {}
impl<T: Base> Marker for T {}
impl Marker for i32 {}

fn requires_marker<T: Marker>(value: &T) {}

fn main() {
    let i: i32 = 0;
    let u: u32 = 0;
    requires_marker(&i); // fine, i32 is unrelated to Base
    requires_marker(&u); // error: the trait `Base` is not implemented for the type `u32`
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-trait-systemArea: Trait systemT-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