Uh oh!
There was an error while loading. Please reload this page.
Implement suggestions for traits to import. - #21008
Conversation
rust-highfive
commented
Jan 12, 2015
r? @pcwalton (rust_highfive has picked a reviewer for you, use r? to override) |
huonw
commented
Jan 12, 2015
This... isn't quite ready yet. The test's full output is: In particular: it lists private traits too. |
huonw
commented
Jan 12, 2015
(Also, the first help's wording is awkward.) Would appreciate any guidance for either. |
nagisa
commented
Jan 12, 2015
Repeating the span for each help message sounds redundant. |
There was a problem hiding this comment.
you may want to filter out private methods here ( meth.vis )
There was a problem hiding this comment.
It's a trait, so there's no distinction.
huonw
commented
Jan 12, 2015
Improved it slightly, but it has the reexported path backwards (i.e. filtering by visibility removed the no-method-suggested-traits.rs:23:10:23:18 error:type `u32` does not implement any method in scope named `method`
no-method-suggested-traits.rs:231u32.method();
^~~~~~~~
no-method-suggested-traits.rs:23:10:23:18 help: methods from traits can only be called if the trait is implemented and in scope; the following traits define a method `method`:
no-method-suggested-traits.rs:231u32.method();
^~~~~~~~
no-method-suggested-traits.rs:17:5:19:6 help: candidate #1: `foo::Bar`
no-method-suggested-traits.rs:17traitBar{//~ HELP `foo::Bar`
no-method-suggested-traits.rs:18fnmethod(&self);
no-method-suggested-traits.rs:19}no-method-suggested-traits.rs:23:10:23:18 help: candidate #2: `no_method_suggested_traits::foo::PubPub`
no-method-suggested-traits.rs:231u32.method();
^~~~~~~~
no-method-suggested-traits.rs:23:10:23:18 help: candidate #3: `no_method_suggested_traits::reexport::Reexported`
no-method-suggested-traits.rs:231u32.method();
^~~~~~~~
error: aborting due to previous error |
There was a problem hiding this comment.
goodness but do we need some helpers for these kinds of things...
nikomatsakis
commented
Jan 12, 2015
Also, let's pull this code into its own file |
For a call like `foo.bar()` where the method `bar` can't be resolved, the compiler will search for traits that have methods with name `bar` to give a more informative error, providing a list of possibilities. Closesrust-lang#7643.
huonw
commented
Jan 14, 2015
Updated with tweaks and better organisation. The test output now looks like: |
huonw
commented
Jan 14, 2015
I've made a few attempts to e.g. extract whether a non-local trait can be accessed from the current crate but I have not been able to achieve it in a correct-enough way as yet. |
nikomatsakis
commented
Jan 14, 2015
@huonw do you find this is a big issue in practice? I would have expected we could kind of just suggest everything and the user can sort it out (and/or leave the screening of unreachable traits as a fixme). |
nikomatsakis
commented
Jan 14, 2015
anyway, I think we could land the code as is, but with some relatively simple tweaks we could at least indicate whether the trait is implemented -- so we could do something like this, only print out the traits that are implemented but not imported, and if none are implemented, suggest traits to implement. That's probably good enough. |
huonw
commented
Jan 16, 2015
Updated again, now with is-trait-implemented filtering. |
If `a.method();` can't be resolved, we first look for implemented traits globally and suggest those. If there are no such traits found, we only then fall back to suggesting from the unfiltered list of traits.
nikomatsakis
commented
Jan 16, 2015
Nice, I'll read over the code shortly. I think we should modify the error message to make it clearer what it means to be "in scope" -- like we should say "try adding |
nikomatsakis
commented
Jan 16, 2015
So I had a few nits on huonw@0a55aac but @huonw said he wouldn't be around much over the next two days. So I'm giving
Nonetheless, I think this is a big step up in clarify, so I'd like to land. |
For a call like
foo.bar()where the methodbarcan't be resolved,the compiler will search for traits that have methods with name
bartogive a more informative error, providing a list of possibilities.
Closes#7643.