Change:
Variables can be marked as unused by prepending with an underscore. If at some point such a variable is used again, the compiler suggests to name the use , even though every single time I have encountered this, what I wanted is to change the definition of to . () Errors:
I feel we should have a counterpart to the unused lint that checks for variables that are used but use the unused bar convention. That wouldn't be useful for the case presented here where you're using an unused bar for the first time, but seems like a reasonable addition.
Such a lint is problematic within macros or other compiler-expanded code, since it's a common pattern to work around not knowing if there are any uses by naming the variables appropriately (for an example look at the loop lowering code)
I agree but I'm pretty sure that most lints should ignore code with spans in macro context already.
Hi, I'd like to work on this!
sorry for not responding earlier. I only have very broad instructions right now, but don't hesitate to ask here or on the stream on zulip if you need more help. the place where the diagnostic "a local variable with a similar name exists" is emitted note that the "local variable" part may be a placeholder and the rest of the string might be broken across multiple lines if that place has more info than just the name of the local variable not, add a to whatever datastructure holds the name I'm not sure how the name is obtained right now, but there should be a way to get at the there, too. E.g. if the name is an , then it has a field. emitting the "similar name" diagnostic, first check whether the suggested name starts with an underscore, but the name used in the code does not that chek fails, keep the old message , emit the suggestion not on the span that it is currently emitted on, but on the definition span (and change the suggestion to remove the underscore)
Hi I've already done most of that :) I think I'll have a working PR next week.
I can work on this if you guys are caught up with something else :)
sure. Just once you start working on it. Maybe you can even get the WIP branch from fork

Discussion:
), ); } <ins> let (span, sugg, post) = if let SuggestionTarget::SimilarlyNamed = suggestion.target && let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(span) && let Some(span) = suggestion.span && let Some(candidate) = suggestion.candidate.as_str().strip_prefix("_") && snippet == candidate { // When the suggested binding change would be from `x` to `_x`, suggest changing the // original binding definition instead. (#60164) (span, snippet, ", consider changing it") } else { (span, suggestion.candidate.to_string(), "") }; </ins> let msg = match suggestion.target { SuggestionTarget::SimilarlyNamed => format!( <del> "{} {} with a similar name exists", </del> <ins> "{} {} with a similar name exists{post}", </ins> suggestion.res.article(), suggestion.res.descr() ),

format!("maybe you meant this {}", suggestion.res.descr()) } }; <del> err.span_suggestion(span, msg, suggestion.candidate, Applicability::MaybeIncorrect); </del> <ins> err.span_suggestion(span, msg, sugg, Applicability::MaybeIncorrect); </ins> true }

<ins> // run-rustfix fn main() { let x = 42; //~ HELP let _y = x; //~ ERROR } </ins>

<ins> // run-rustfix fn main() { let _x = 42; //~ HELP let _y = x; //~ ERROR } </ins>

<ins> error[E0425]: cannot find value `x` in this scope --> $DIR/silenced-binding-typo.rs:4:14 | LL |     let _y = x; |              ^ | help: a local variable with a similar name exists, consider changing it | LL |     let x = 42; |         ~ error: aborting due to previous error For more information about this error, try `rustc --explain E0425`. </ins>