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

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

Closed
pnkfelix opened this issue Aug 14, 2013 · 2 comments
Closed
Labels
A-diagnostics Area: Messages for errors, warnings, and lints

Comments

@pnkfelix
Copy link
Member

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.)

@emberian
Copy link
Member

Added to my todo list.

@pnkfelix
Copy link
Member Author

this is actually a dupe of #7643 ; I'll close this in favor of that.

flip1995 pushed a commit to flip1995/rust that referenced this issue Mar 24, 2022
flip1995 pushed a commit to flip1995/rust that referenced this issue Mar 24, 2022
Fix `unncessary_to_owned` false positive

Fix rust-lang#8507

changelog: none
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
Projects
None yet
Development

No branches or pull requests

2 participants