Skip to content

better error message for invoking method from known (but un-use'd) trait #8507

@pnkfelix

Description

@pnkfelix

Code:

// (deliberately commented out to show error msg)
// use m::T;
mod m {
    pub trait T { fn hi(&self) -> ~str; }
}
struct S;
impl m::T for S { fn hi(&self) -> ~str { ~"Hello World" } }
fn main() {
    let s = S;
    println(s.hi());
}

Compiler error message:

/tmp/implerr.rs:10:12: 10:19 error: type `S` does not implement any method in scope named `hi`
/tmp/implerr.rs:10     println(s.hi());
                               ^~~~~~~
error: aborting due to previous error

We can do better here; e.g. the compiler could scan the known traits implemented for S and suggest that the user use m::T here. (I often forget to add the use, and thus keep hitting this.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lints

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions