Make non-found module name optional
No longer uses a magic string for missing or root module.
This commit is contained in:
parent
da569fa9dd
commit
1dcfd144b9
2 changed files with 8 additions and 8 deletions
|
@ -4062,7 +4062,7 @@ fn show_candidates(err: &mut DiagnosticBuilder,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A somewhat inefficient routine to obtain the name of a module.
|
/// A somewhat inefficient routine to obtain the name of a module.
|
||||||
fn module_to_string(module: Module) -> String {
|
fn module_to_string(module: Module) -> Option<String> {
|
||||||
let mut names = Vec::new();
|
let mut names = Vec::new();
|
||||||
|
|
||||||
fn collect_mod(names: &mut Vec<Ident>, module: Module) {
|
fn collect_mod(names: &mut Vec<Ident>, module: Module) {
|
||||||
|
@ -4080,12 +4080,12 @@ fn module_to_string(module: Module) -> String {
|
||||||
collect_mod(&mut names, module);
|
collect_mod(&mut names, module);
|
||||||
|
|
||||||
if names.is_empty() {
|
if names.is_empty() {
|
||||||
return "???".to_string();
|
return None;
|
||||||
}
|
}
|
||||||
names_to_string(&names.into_iter()
|
Some(names_to_string(&names.into_iter()
|
||||||
.rev()
|
.rev()
|
||||||
.map(|n| dummy_spanned(n))
|
.map(|n| dummy_spanned(n))
|
||||||
.collect::<Vec<_>>())
|
.collect::<Vec<_>>()))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn err_path_resolution() -> PathResolution {
|
fn err_path_resolution() -> PathResolution {
|
||||||
|
|
|
@ -524,7 +524,7 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
|
||||||
fn resolve_import(&mut self, directive: &'b ImportDirective<'b>) -> bool {
|
fn resolve_import(&mut self, directive: &'b ImportDirective<'b>) -> bool {
|
||||||
debug!("(resolving import for module) resolving import `{}::...` in `{}`",
|
debug!("(resolving import for module) resolving import `{}::...` in `{}`",
|
||||||
names_to_string(&directive.module_path[..]),
|
names_to_string(&directive.module_path[..]),
|
||||||
module_to_string(self.current_module));
|
module_to_string(self.current_module).unwrap_or("???".to_string()));
|
||||||
|
|
||||||
self.current_module = directive.parent;
|
self.current_module = directive.parent;
|
||||||
|
|
||||||
|
@ -773,10 +773,10 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
|
||||||
None => "".to_owned(),
|
None => "".to_owned(),
|
||||||
};
|
};
|
||||||
let module_str = module_to_string(module);
|
let module_str = module_to_string(module);
|
||||||
let msg = if &module_str == "???" {
|
let msg = if let Some(module_str) = module_str {
|
||||||
format!("no `{}` in the root{}", ident, lev_suggestion)
|
|
||||||
} else {
|
|
||||||
format!("no `{}` in `{}`{}", ident, module_str, lev_suggestion)
|
format!("no `{}` in `{}`{}", ident, module_str, lev_suggestion)
|
||||||
|
} else {
|
||||||
|
format!("no `{}` in the root{}", ident, lev_suggestion)
|
||||||
};
|
};
|
||||||
Some((span, msg))
|
Some((span, msg))
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue