-
Notifications
You must be signed in to change notification settings - Fork 13.3k
rustc should provide a suggestion when using a type/trait from a sibling module that isn't imported #21221
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
Comments
Sorry, forgot to say: |
Perhaps it should print a list of modules in the local crate that define something with that name. |
That would be wonderful. |
@kmcallister You marked this easy, can you give me an idea of what might be involved plus some pointers to the relevant code? If it is simple enough, I might be able to knock this out. |
Sounds similar to #21008. |
If this is still open (I don't see suggestions in the beta channel), I'd like to take a shot. |
Since it doesn't seem like there's much activity around this bug, let me try to revive it. Please correct me if this is not the desired behavior: mod mul1 {
pub trait Mul {}
}
mod mul2 {
pub trait Mul {}
}
#[derive(Debug)]
struct Foo;
// When we comment the next line:
use mul1::Mul;
// We get the following error for the `impl` below:
// error: use of undeclared trait name `Mul` [E0405]
// Ideally, when this bug is fixed, we would like to see:
// error: use of undeclared trait name `Mul` [E0405]
// note: Possible alternatives are:
// use mul1::Mul; // from module mul1 in this crate <or>
// use mul2::Mul; // from module mul1 in this crate <or>
// use std::ops::Mul; // from the standard library <or>
// use other_crate::Mul; // from external crate other_crate ...
impl Mul for Foo { }
fn main() {
let foo = Foo;
println!("Hello, {:?}!", foo);
} So, I imagine, in the ideal case,
Right? As for the implementation, I imagine I can start from the suggest_traits_to_import method in suggest.rs. WDYT? |
I feel like changing the message to "trait name |
But yes if we wanted to all out and give suggestions, I think the code you pointed out would be a logical starting point, though of course it is harvesting all traits that have a method with the given name, which is somewhat more complicated. |
Thank you for the feedback @nikomatsakis -- if all else fails, I will PR an update to the error message. Outdated:
|
Some progress on this: VladUreche@f4abc9d |
Okay, sloppy implementation, but I have a solution:
Commit is VladUreche@9a4c9e5. |
The last commit adds recommendations for both resolution errors in the bug description and the new message is more comprehensible, IMO: master...VladUreche:issue/21221 @fitzgen @nikomatsakis are you okay with the ouput for this example? |
Vlad, I left some comments on the commit. I didn't read it too closely but On Sun, Feb 14, 2016 at 9:21 PM, Vlad Ureche [email protected]
|
@nikomatsakis Thank you for the feedback! All your comments should be addressed by the latest version of this commit, VladUreche@5f1b4a4, where I had a chance to clean things up. For the burden of maintaining the additional lookup method, it makes sense to delay the PR (#31674) if there's a major refactoring going on. On my side, I can port the code over once the dust settles, just ping me. |
cc @jseyfried @petrochenkov, resident resolve experts :) |
oops! |
Thanks @nikomatsakis! |
This commit adds functionality that allows the name resolution pass to search for entities (traits/types/enums/structs) by name, in order to show recommendations along with the errors. For now, only E0405 and E0412 have suggestions attached, as per the request in bug rust-lang#21221, but it's likely other errors can also benefit from the ability to generate suggestions.
This commit adds functionality that allows the name resolution pass to search for entities (traits/types/enums/structs) by name, in order to show recommendations along with the errors. For now, only E0405 and E0412 have suggestions attached, as per the request in bug #21221, but it's likely other errors can also benefit from the ability to generate suggestions.
@nikomatsakis @jseyfried Should we close this bug, or do you want to keep it open for the extensions that could be added? |
I think we should close it |
Here is two examples in one, a trait and a type:
It would be nice UX to say something like "did you forget to import module::Type?" or something.
The text was updated successfully, but these errors were encountered: