]> git.lizzy.rs Git - rust.git/commitdiff
Do not suggest things named underscore
authorYuki Okushi <huyuumi.dev@gmail.com>
Sat, 1 Feb 2020 19:40:55 +0000 (04:40 +0900)
committerYuki Okushi <huyuumi.dev@gmail.com>
Sat, 1 Feb 2020 19:55:37 +0000 (04:55 +0900)
src/librustc_resolve/diagnostics.rs
src/test/ui/resolve/typo-suggestion-named-underscore.rs [new file with mode: 0644]
src/test/ui/resolve/typo-suggestion-named-underscore.stderr [new file with mode: 0644]

index b762e0b08ac044bbeb420814fb5428aac5c26ee8..1705736a67c4322916b4ece82acfbf4e4b2e1962 100644 (file)
@@ -769,6 +769,11 @@ fn lookup_import_candidates_from_module<FilterFn>(
         span: Span,
     ) -> bool {
         if let Some(suggestion) = suggestion {
+            // We shouldn't suggest underscore.
+            if suggestion.candidate == kw::Underscore {
+                return false;
+            }
+
             let msg = format!(
                 "{} {} with a similar name exists",
                 suggestion.res.article(),
diff --git a/src/test/ui/resolve/typo-suggestion-named-underscore.rs b/src/test/ui/resolve/typo-suggestion-named-underscore.rs
new file mode 100644 (file)
index 0000000..a2b05db
--- /dev/null
@@ -0,0 +1,14 @@
+const _: () = ();
+
+fn main() {
+    a // Shouldn't suggest underscore
+    //~^ ERROR: cannot find value `a` in this scope
+}
+
+trait Unknown {}
+
+#[allow(unused_imports)]
+use Unknown as _;
+
+fn foo<T: A>(x: T) {} // Shouldn't suggest underscore
+//~^ ERROR: cannot find trait `A` in this scope
diff --git a/src/test/ui/resolve/typo-suggestion-named-underscore.stderr b/src/test/ui/resolve/typo-suggestion-named-underscore.stderr
new file mode 100644 (file)
index 0000000..65d1b08
--- /dev/null
@@ -0,0 +1,16 @@
+error[E0425]: cannot find value `a` in this scope
+  --> $DIR/typo-suggestion-named-underscore.rs:4:5
+   |
+LL |     a // Shouldn't suggest underscore
+   |     ^ not found in this scope
+
+error[E0405]: cannot find trait `A` in this scope
+  --> $DIR/typo-suggestion-named-underscore.rs:13:11
+   |
+LL | fn foo<T: A>(x: T) {} // Shouldn't suggest underscore
+   |           ^ not found in this scope
+
+error: aborting due to 2 previous errors
+
+Some errors have detailed explanations: E0405, E0425.
+For more information about an error, try `rustc --explain E0405`.