From 3770cf7abf2c62667e8b197be1bea3665e75a8f1 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Thu, 29 Feb 2024 12:06:51 +0100 Subject: [PATCH 1/2] Improve suggestion to rename type starting with underscore to make it more obvious what is actually suggested --- compiler/rustc_resolve/src/diagnostics.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_resolve/src/diagnostics.rs b/compiler/rustc_resolve/src/diagnostics.rs index 222dd69dbc48e..6e8499be9e8c9 100644 --- a/compiler/rustc_resolve/src/diagnostics.rs +++ b/compiler/rustc_resolve/src/diagnostics.rs @@ -1571,9 +1571,10 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { { // When the suggested binding change would be from `x` to `_x`, suggest changing the // original binding definition instead. (#60164) - (span, snippet, ", consider changing it") + let post = format!(", consider renaming `{}` into `{snippet}`", suggestion.candidate); + (span, snippet, post) } else { - (span, suggestion.candidate.to_string(), "") + (span, suggestion.candidate.to_string(), String::new()) }; let msg = match suggestion.target { SuggestionTarget::SimilarlyNamed => format!( From 451fd9815393b1b1ed8f28f27929645b31550a3f Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Thu, 29 Feb 2024 12:07:35 +0100 Subject: [PATCH 2/2] Update UI test checking suggestion message to rename type starting with underscore --- tests/ui/suggestions/silenced-binding-typo.stderr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ui/suggestions/silenced-binding-typo.stderr b/tests/ui/suggestions/silenced-binding-typo.stderr index 8dbd94208d614..c362d00c713a2 100644 --- a/tests/ui/suggestions/silenced-binding-typo.stderr +++ b/tests/ui/suggestions/silenced-binding-typo.stderr @@ -4,7 +4,7 @@ error[E0425]: cannot find value `x` in this scope LL | let _y = x; | ^ | -help: a local variable with a similar name exists, consider changing it +help: a local variable with a similar name exists, consider renaming `_x` into `x` | LL | let x = 42; | ~