diff options
| author | Dominik Winecki <dominikwinecki@gmail.com> | 2018-01-16 14:47:14 -0500 |
|---|---|---|
| committer | Dominik Winecki <dominikwinecki@gmail.com> | 2018-01-16 14:47:14 -0500 |
| commit | 1dcfd144b95dedce607c764dec6c5931f5be0ceb (patch) | |
| tree | 540cc0922f0217ce175c7bbf369cc5c6736832ef | |
| parent | da569fa9ddf8369a9809184d43c600dc06bd4b4d (diff) | |
| download | rust-1dcfd144b95dedce607c764dec6c5931f5be0ceb.tar.gz rust-1dcfd144b95dedce607c764dec6c5931f5be0ceb.zip | |
Make non-found module name optional
No longer uses a magic string for missing or root module.
| -rw-r--r-- | src/librustc_resolve/lib.rs | 8 | ||||
| -rw-r--r-- | src/librustc_resolve/resolve_imports.rs | 8 |
2 files changed, 8 insertions, 8 deletions
diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index 0a29441cef7..71bebc32732 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -4062,7 +4062,7 @@ fn show_candidates(err: &mut DiagnosticBuilder, } /// 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(); 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); if names.is_empty() { - return "???".to_string(); + return None; } - names_to_string(&names.into_iter() + Some(names_to_string(&names.into_iter() .rev() .map(|n| dummy_spanned(n)) - .collect::<Vec<_>>()) + .collect::<Vec<_>>())) } fn err_path_resolution() -> PathResolution { diff --git a/src/librustc_resolve/resolve_imports.rs b/src/librustc_resolve/resolve_imports.rs index 132119e961b..b03f040ba98 100644 --- a/src/librustc_resolve/resolve_imports.rs +++ b/src/librustc_resolve/resolve_imports.rs @@ -524,7 +524,7 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> { fn resolve_import(&mut self, directive: &'b ImportDirective<'b>) -> bool { debug!("(resolving import for module) resolving import `{}::...` in `{}`", 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; @@ -773,10 +773,10 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> { None => "".to_owned(), }; let module_str = module_to_string(module); - let msg = if &module_str == "???" { - format!("no `{}` in the root{}", ident, lev_suggestion) - } else { + let msg = if let Some(module_str) = module_str { format!("no `{}` in `{}`{}", ident, module_str, lev_suggestion) + } else { + format!("no `{}` in the root{}", ident, lev_suggestion) }; Some((span, msg)) } else { |
