suggestion for typoed crate or module

avoid suggesting the same name

sort candidates

fix a message

use `opt_def_id` instead of `def_id`

move `find_similarly_named_module_or_crate` to rustc_resolve/src/diagnostics.rs
This commit is contained in:
Takayuki Maeda 2021-09-29 13:55:24 +09:00
parent d7539a6af0
commit f819e6d59c
5 changed files with 109 additions and 1 deletions

View file

@ -1277,6 +1277,34 @@ impl<'a> Resolver<'a> {
err.emit();
}
crate fn find_similarly_named_module_or_crate(
&mut self,
ident: Symbol,
current_module: &Module<'a>,
) -> Option<Symbol> {
let mut candidates = self
.extern_prelude
.iter()
.map(|(ident, _)| ident.name)
.chain(
self.module_map
.iter()
.filter(|(_, module)| {
current_module.is_ancestor_of(module) && !ptr::eq(current_module, *module)
})
.map(|(_, module)| module.kind.name())
.flatten(),
)
.filter(|c| !c.to_string().is_empty())
.collect::<Vec<_>>();
candidates.sort();
candidates.dedup();
match find_best_match_for_name(&candidates, ident, None) {
Some(sugg) if sugg == ident => None,
sugg => sugg,
}
}
}
impl<'a, 'b> ImportResolver<'a, 'b> {