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

Hint when using a static method on an instance is wrong #29121

Closed
jdm opened this issue Oct 17, 2015 · 3 comments
Closed

Hint when using a static method on an instance is wrong #29121

jdm opened this issue Oct 17, 2015 · 3 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints

Comments

@jdm
Copy link
Contributor

jdm commented Oct 17, 2015

I wrote Box::new(telemetry_t::new()).into_raw() and got this output:

src/lib.rs:41:34: 41:44 error: no method named `into_raw` found for type `Box<telemetry_t>` in the current scope
src/lib.rs:41     Box::new(telemetry_t::new()).into_raw()
                                               ^~~~~~~~~~
src/lib.rs:41:34: 41:44 note: found defined static methods, maybe a `self` is missing?
src/lib.rs:41:34: 41:44 note: candidate #1 is defined in an impl for the type `Box<_>`
src/lib.rs:41     Box::new(telemetry_t::new()).into_raw()
                                               ^~~~~~~~~~

The hint in particular was confusing, since it is targeted at developers who created the impl and forgot to provide a self argument, rather than consumers of an impl that is specifically designed to be static.

@jdm jdm added the A-diagnostics Area: Messages for errors, warnings, and lints label Oct 17, 2015
@Manishearth
Copy link
Member

We should probably structure this so that both suggestions are shown. Alternatively, suggest changing the method only when the method is defined in the local crate.

@birkenfeld
Copy link
Contributor

Current compiler message is slightly different:

x.rs:3:15: 3:23 error: no method named `into_raw` found for type `Box<_>` in the current scope
x.rs:3     let y = x.into_raw();
                     ^~~~~~~~
x.rs:3:15: 3:23 note: found the following associated functions; to be used as methods, functions must have a `self` parameter
x.rs:3:15: 3:23 note: candidate #1 is defined in an impl for the type `Box<_>`
x.rs:3     let y = x.into_raw();
                     ^~~~~~~~

The snippet given for the "candidate #1" seems wrong, shouldn't it present the definition of into_raw (or, if that is not available since it's from std, nothing)?

birkenfeld added a commit to birkenfeld/rust that referenced this issue May 3, 2016
…back

In case we cannot produce a span for the location of the definition,
just do not show a span at all.

cc: rust-lang#29121
bors added a commit that referenced this issue May 3, 2016
typeck: when suggesting associated fns, do not show call site as fallback

In case we cannot produce a span for the location of the definition, just do not show a span at all.

cc: #29121
@jdm
Copy link
Contributor Author

jdm commented Sep 25, 2016

Fixed by #33330.

@jdm jdm closed this as completed Sep 25, 2016
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

3 participants