},
}
}
- assert!(self.span.is_some(), "a file can't have no items and emit suggestions");
}
}
};
visit::walk_crate(&mut finder, krate);
if !candidates.is_empty() {
- let span = finder.span.expect("did not find module");
- show_candidates(&mut err, span, &candidates, better, finder.found_use);
+ show_candidates(&mut err, finder.span, &candidates, better, finder.found_use);
}
err.emit();
}
/// entities with that name in all crates. This method allows outputting the
/// results of this search in a programmer-friendly way
fn show_candidates(err: &mut DiagnosticBuilder,
- span: Span,
+ // This is `None` if all placement locations are inside expansions
+ span: Option<Span>,
candidates: &[ImportSuggestion],
better: bool,
found_use: bool) {
};
let msg = format!("possible {}candidate{} into scope", better, msg_diff);
- for candidate in &mut path_strings {
- // produce an additional newline to separate the new use statement
- // from the directly following item.
- let additional_newline = if found_use {
- ""
- } else {
- "\n"
- };
- *candidate = format!("use {};\n{}", candidate, additional_newline);
- }
+ if let Some(span) = span {
+ for candidate in &mut path_strings {
+ // produce an additional newline to separate the new use statement
+ // from the directly following item.
+ let additional_newline = if found_use {
+ ""
+ } else {
+ "\n"
+ };
+ *candidate = format!("use {};\n{}", candidate, additional_newline);
+ }
- err.span_suggestions(span, &msg, path_strings);
+ err.span_suggestions(span, &msg, path_strings);
+ } else {
+ let mut msg = msg;
+ msg.push(':');
+ for candidate in path_strings {
+ msg.push('\n');
+ msg.push_str(&candidate);
+ }
+ }
}
/// A somewhat inefficient routine to obtain the name of a module.