Auto merge of #36289 - euclio:self-suggestion, r=jseyfried
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. Fixes #34191. Thank you for the help @jseyfried!
This commit is contained in:
commit
f707582a43
@ -588,7 +588,19 @@ fn finalize_import(&mut self, directive: &'b ImportDirective<'b>) -> ResolveResu
|
||||
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 {
|
||||
|
@ -35,3 +35,23 @@ pub mod baz {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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() {}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user