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

resolve: Suggest use self when import resolves #36289

Merged
merged 2 commits into from
Sep 7, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/librustc_resolve/resolve_imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,19 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
let module = match module_result {
Success(module) => module,
Indeterminate => return Indeterminate,
Failed(err) => return Failed(err),
Failed(err) => {
let self_module = self.module_map[&self.current_module.normal_ancestor_id.unwrap()];

let resolve_from_self_result = self.resolve_module_path_from_root(
&self_module, &module_path, 0, Some(span));

return if let Success(_) = resolve_from_self_result {
let msg = format!("Did you mean `self::{}`?", &names_to_string(module_path));
Failed(Some((span, msg)))
} else {
Failed(err)
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

optional nit: I think this match would look better as an if let (i.e. if let Success(_) = self_result { ... }).

},
};

let (name, value_result, type_result) = match directive.subclass {
Expand Down
20 changes: 20 additions & 0 deletions src/test/compile-fail/unresolved-import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,23 @@ mod food {
}
}
}

mod m {
enum MyEnum {
MyVariant
}

use MyEnum::*; //~ ERROR unresolved import `MyEnum::*` [E0432]
//~^ Did you mean `self::MyEnum`?
}

mod items {
enum Enum {
Variant
}

use Enum::*; //~ ERROR unresolved import `Enum::*` [E0432]
//~^ Did you mean `self::Enum`?

fn item() {}
}