diff --git a/src/librustc_resolve/resolve_imports.rs b/src/librustc_resolve/resolve_imports.rs index 875d6745f6b2e..90c17866583a7 100644 --- a/src/librustc_resolve/resolve_imports.rs +++ b/src/librustc_resolve/resolve_imports.rs @@ -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) + }; + }, }; let (name, value_result, type_result) = match directive.subclass { diff --git a/src/test/compile-fail/unresolved-import.rs b/src/test/compile-fail/unresolved-import.rs index d1254f3f5241b..0a9a437569730 100644 --- a/src/test/compile-fail/unresolved-import.rs +++ b/src/test/compile-fail/unresolved-import.rs @@ -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() {} +}