about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/librustc_resolve/lib.rs12
-rw-r--r--src/test/ui/crate-in-paths.rs11
-rw-r--r--src/test/ui/crate-in-paths.stderr13
3 files changed, 33 insertions, 3 deletions
diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs
index 992ea12ffa2..96f92299fd6 100644
--- a/src/librustc_resolve/lib.rs
+++ b/src/librustc_resolve/lib.rs
@@ -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);
diff --git a/src/test/ui/crate-in-paths.rs b/src/test/ui/crate-in-paths.rs
new file mode 100644
index 00000000000..b368f0cb4b6
--- /dev/null
+++ b/src/test/ui/crate-in-paths.rs
@@ -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]
+}
diff --git a/src/test/ui/crate-in-paths.stderr b/src/test/ui/crate-in-paths.stderr
new file mode 100644
index 00000000000..207f9599230
--- /dev/null
+++ b/src/test/ui/crate-in-paths.stderr
@@ -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`.