Skip to content

Make non-found module name optional #47498

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/librustc_resolve/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions src/librustc_resolve/resolve_imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a test for this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC, there was an issue about this ??? but I can't find it right away.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, ok, this is not a new message, just refactoring.

};
Some((span, msg))
} else {
Expand Down