Skip to content

unhelpful error message for missing (first) self param on traiit method #7575

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

Closed
jbclements opened this issue Jul 3, 2013 · 5 comments · Fixed by #13685
Closed

unhelpful error message for missing (first) self param on traiit method #7575

jbclements opened this issue Jul 3, 2013 · 5 comments · Fixed by #13685
Labels
E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. P-low Low priority

Comments

@jbclements
Copy link
Contributor

This code:

trait CtxtFn{
    pub fn f9(uint) -> uint;
}

pub fn use_ctxtfn<T : CtxtFn>(cf: T) -> uint {
    cf.f9(342)
}

...signals the error message:

error: type `T` does not implement any method in scope named `f9`

...which is kind of crazy, because T is bounded by CtxtFn, and I can see the definition of f9.
<before reading on: can you see the problem?>

I tore my hair out for quite a while before realizing I'd forgotten the "self" parameter on the decl of f9. This is just a papercut, but it seems like a big one to me. Fixing this--that is, signalling an error like "method f9 is declared without a self parameter"--would presumably require a pass in resolve which scanned for methods without a self parameter.

@jdm
Copy link
Contributor

jdm commented Jul 4, 2013

I too lost a bunch of time to this papercut recently.

@metajack
Copy link
Contributor

metajack commented Sep 5, 2013

A complete test case:

trait CtxtFn {
    fn f9(uint) -> uint;
}

fn use_ctxtfn<T: CtxtFn>(cf: T) -> uint {
    cf.f9(342)
}

fn main() {
}

This is still an issue. Since multiple rust devs have hit this themselves, nominating for production ready.

@catamorphism
Copy link
Contributor

Accepted for production-ready

@jdm
Copy link
Contributor

jdm commented Mar 14, 2014

The relevant code is in check_method_call (http://mxr.mozilla.org/rust/source/src/librustc/middle/typeck/check/mod.rs#1916). I think performing another check for a static trait method that otherwise matches would make a ton of sense here. Perhaps using lookup_in_trait (http://mxr.mozilla.org/rust/source/src/librustc/middle/typeck/check/method.rs#122) which has an optional self expression argument?

@jdm jdm removed the E-easy label Mar 14, 2014
@pnkfelix
Copy link
Member

Assigning P-low, not 1.0 blocker.

bors added a commit that referenced this issue May 3, 2014
Closes #7575.

I don't think the change from a contains lookup to an iteration of the HashSet in the resolver should be much of a burden as the set of methods with the same name should be relatively small.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. P-low Low priority
Projects
None yet
5 participants