Skip to content

Commit d0ed795

Browse files
authored
Unrolled build for rust-lang#121792
Rollup merge of rust-lang#121792 - GuillaumeGomez:improve-suggestion, r=michaelwoerister Improve renaming suggestion when item starts with underscore Fixes rust-lang#121776. It goes from: ```terminal error[E0433]: failed to resolve: use of undeclared type `Foo` --> src/foo.rs:6:13 | 6 | let _ = Foo::Bar; | ^^^ use of undeclared type `Foo` | help: an enum with a similar name exists, consider changing it | 1 | enum Foo { | ~~~ ``` to: ```terminal error[E0433]: failed to resolve: use of undeclared type `Foo` --> foo.rs:6:13 | 6 | let _ = Foo::Bar; | ^^^ use of undeclared type `Foo` | help: an enum with a similar name exists, consider renaming `_Foo` into `Foo` | 1 | enum Foo { | ~~~ error: aborting due to 1 previous error ```
2 parents 71a7b66 + 451fd98 commit d0ed795

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

compiler/rustc_resolve/src/diagnostics.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1585,9 +1585,10 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
15851585
{
15861586
// When the suggested binding change would be from `x` to `_x`, suggest changing the
15871587
// original binding definition instead. (#60164)
1588-
(span, snippet, ", consider changing it")
1588+
let post = format!(", consider renaming `{}` into `{snippet}`", suggestion.candidate);
1589+
(span, snippet, post)
15891590
} else {
1590-
(span, suggestion.candidate.to_string(), "")
1591+
(span, suggestion.candidate.to_string(), String::new())
15911592
};
15921593
let msg = match suggestion.target {
15931594
SuggestionTarget::SimilarlyNamed => format!(

tests/ui/suggestions/silenced-binding-typo.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0425]: cannot find value `x` in this scope
44
LL | let _y = x;
55
| ^
66
|
7-
help: a local variable with a similar name exists, consider changing it
7+
help: a local variable with a similar name exists, consider renaming `_x` into `x`
88
|
99
LL | let x = 42;
1010
| ~

0 commit comments

Comments
 (0)