From: Yuki Okushi Date: Sat, 1 Feb 2020 19:40:55 +0000 (+0900) Subject: Do not suggest things named underscore X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;ds=inline;h=726568bd1b4ac9af4dc84816eae1957c3d2bfc32;p=rust.git Do not suggest things named underscore --- diff --git a/src/librustc_resolve/diagnostics.rs b/src/librustc_resolve/diagnostics.rs index b762e0b08ac..1705736a67c 100644 --- a/src/librustc_resolve/diagnostics.rs +++ b/src/librustc_resolve/diagnostics.rs @@ -769,6 +769,11 @@ fn lookup_import_candidates_from_module( 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 index 00000000000..a2b05db0351 --- /dev/null +++ b/src/test/ui/resolve/typo-suggestion-named-underscore.rs @@ -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(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 index 00000000000..65d1b084a3a --- /dev/null +++ b/src/test/ui/resolve/typo-suggestion-named-underscore.stderr @@ -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(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`.