resolve suggestions should use create:: when enabled

fixes #51212
This commit is contained in:
Douglas Campos 2018-06-09 14:04:44 +00:00
parent b5590423e6
commit df55b7c28f
3 changed files with 33 additions and 3 deletions

View File

@ -4488,7 +4488,7 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
for UseError { mut err, candidates, node_id, better } in self.use_injections.drain(..) {
let (span, found_use) = UsePlacementFinder::check(krate, node_id);
if !candidates.is_empty() {
show_candidates(&mut err, span, &candidates, better, found_use);
show_candidates(&mut err, span, &candidates, better, found_use, self.session.features_untracked().crate_in_paths);
}
err.emit();
}
@ -4702,7 +4702,8 @@ fn show_candidates(err: &mut DiagnosticBuilder,
span: Option<Span>,
candidates: &[ImportSuggestion],
better: bool,
found_use: bool) {
found_use: bool,
crate_in_paths: bool) {
// we want consistent results across executions, but candidates are produced
// by iterating through a hash map, so make sure they are ordered:
@ -4726,7 +4727,12 @@ fn show_candidates(err: &mut DiagnosticBuilder,
} else {
"\n"
};
*candidate = format!("use {};\n{}", candidate, additional_newline);
let crate_prefix = if crate_in_paths {
"crate::"
} else {
""
};
*candidate = format!("use {}{};\n{}", crate_prefix, candidate, additional_newline);
}
err.span_suggestions(span, &msg, path_strings);

View File

@ -0,0 +1,11 @@
#![feature(crate_visibility_modifier)]
#![feature(crate_in_paths)]
mod bar {
crate struct Foo;
}
fn main() {
Foo;
//~^ ERROR cannot find value `Foo` in this scope [E0425]
}

View File

@ -0,0 +1,13 @@
error[E0425]: cannot find value `Foo` in this scope
--> $DIR/crate-in-paths.rs:9:5
|
LL | Foo;
| ^^^ not found in this scope
help: possible candidate is found in another module, you can import it into scope
|
LL | use crate::bar::Foo;
|
error: aborting due to previous error
For more information about this error, try `rustc --explain E0425`.