resolve: Suggest use self when import resolves

Improves errors messages by replacing "Maybe a missing `extern crate`" messages
with "Did you mean `self::...`" when the `self` import would succeed.
This commit is contained in:
Andy Russell 2016-09-05 21:48:02 -04:00
parent 38824d1061
commit 41ee2e9124
2 changed files with 24 additions and 1 deletions

View file

@ -587,7 +587,21 @@ 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.current_module.clone();
let resolve_from_self_result = self.resolve_module_path_from_root(
&self_module, &module_path, 0, Some(span));
return match resolve_from_self_result {
Success(_) => {
let msg = format!("Did you mean `self::{}`?",
&names_to_string(module_path));
Failed(Some((span, msg)))
},
_ => Failed(err),
};
},
};
let (name, value_result, type_result) = match directive.subclass {

View file

@ -35,3 +35,12 @@ mod food {
}
}
}
mod m {
enum MyEnum {
MyVariant
}
use MyEnum::*; //~ ERROR unresolved import `MyEnum::*` [E0432]
//~^ Did you mean `self::MyEnum`?
}