Skip to content

Commit fb1f01d

Browse files
authored
Rollup merge of #47498 - dominikWin:missing-module-name, r=petrochenkov
Make non-found module name optional No longer uses a magic string for missing or root module.
2 parents a588dcf + 1dcfd14 commit fb1f01d

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

src/librustc_resolve/lib.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -4062,7 +4062,7 @@ fn show_candidates(err: &mut DiagnosticBuilder,
40624062
}
40634063

40644064
/// A somewhat inefficient routine to obtain the name of a module.
4065-
fn module_to_string(module: Module) -> String {
4065+
fn module_to_string(module: Module) -> Option<String> {
40664066
let mut names = Vec::new();
40674067

40684068
fn collect_mod(names: &mut Vec<Ident>, module: Module) {
@@ -4080,12 +4080,12 @@ fn module_to_string(module: Module) -> String {
40804080
collect_mod(&mut names, module);
40814081

40824082
if names.is_empty() {
4083-
return "???".to_string();
4083+
return None;
40844084
}
4085-
names_to_string(&names.into_iter()
4085+
Some(names_to_string(&names.into_iter()
40864086
.rev()
40874087
.map(|n| dummy_spanned(n))
4088-
.collect::<Vec<_>>())
4088+
.collect::<Vec<_>>()))
40894089
}
40904090

40914091
fn err_path_resolution() -> PathResolution {

src/librustc_resolve/resolve_imports.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
524524
fn resolve_import(&mut self, directive: &'b ImportDirective<'b>) -> bool {
525525
debug!("(resolving import for module) resolving import `{}::...` in `{}`",
526526
names_to_string(&directive.module_path[..]),
527-
module_to_string(self.current_module));
527+
module_to_string(self.current_module).unwrap_or("???".to_string()));
528528

529529
self.current_module = directive.parent;
530530

@@ -773,10 +773,10 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
773773
None => "".to_owned(),
774774
};
775775
let module_str = module_to_string(module);
776-
let msg = if &module_str == "???" {
777-
format!("no `{}` in the root{}", ident, lev_suggestion)
778-
} else {
776+
let msg = if let Some(module_str) = module_str {
779777
format!("no `{}` in `{}`{}", ident, module_str, lev_suggestion)
778+
} else {
779+
format!("no `{}` in the root{}", ident, lev_suggestion)
780780
};
781781
Some((span, msg))
782782
} else {

0 commit comments

Comments
 (0)