Skip to content

Commit 87bb0c4

Browse files
authored
Rollup merge of #68740 - JohnTitor:do-not-sugg-underscore, r=Centril
Do not suggest things named underscore Fixes #68719 r? @estebank
2 parents c7332ab + 726568b commit 87bb0c4

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

src/librustc_resolve/diagnostics.rs

+5
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,11 @@ impl<'a> Resolver<'a> {
769769
span: Span,
770770
) -> bool {
771771
if let Some(suggestion) = suggestion {
772+
// We shouldn't suggest underscore.
773+
if suggestion.candidate == kw::Underscore {
774+
return false;
775+
}
776+
772777
let msg = format!(
773778
"{} {} with a similar name exists",
774779
suggestion.res.article(),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
const _: () = ();
2+
3+
fn main() {
4+
a // Shouldn't suggest underscore
5+
//~^ ERROR: cannot find value `a` in this scope
6+
}
7+
8+
trait Unknown {}
9+
10+
#[allow(unused_imports)]
11+
use Unknown as _;
12+
13+
fn foo<T: A>(x: T) {} // Shouldn't suggest underscore
14+
//~^ ERROR: cannot find trait `A` in this scope
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
error[E0425]: cannot find value `a` in this scope
2+
--> $DIR/typo-suggestion-named-underscore.rs:4:5
3+
|
4+
LL | a // Shouldn't suggest underscore
5+
| ^ not found in this scope
6+
7+
error[E0405]: cannot find trait `A` in this scope
8+
--> $DIR/typo-suggestion-named-underscore.rs:13:11
9+
|
10+
LL | fn foo<T: A>(x: T) {} // Shouldn't suggest underscore
11+
| ^ not found in this scope
12+
13+
error: aborting due to 2 previous errors
14+
15+
Some errors have detailed explanations: E0405, E0425.
16+
For more information about an error, try `rustc --explain E0405`.

0 commit comments

Comments
 (0)