1
Fork 0

Improve handling of tmp variable name conflicts

This commit is contained in:
Noah Lev 2022-02-17 14:58:46 -08:00
parent 62b8ea67b7
commit 073010d425
5 changed files with 86 additions and 7 deletions

View file

@ -1325,13 +1325,17 @@ impl<'a> Parser<'a> {
kind: IncDecRecovery,
(pre_span, post_span): (Span, Span),
) {
let mut msg = format!("use `{}= 1` instead", kind.op.chr());
if base_src.trim() == "tmp" {
msg.push_str(" (rename `tmp` so it doesn't conflict with your variable)");
}
err.multipart_suggestion(
&format!("use `{}= 1` instead", kind.op.chr()),
&msg,
vec![
(pre_span, "{ let tmp = ".to_string()),
(post_span, format!("; {} {}= 1; tmp }}", base_src, kind.op.chr())),
],
Applicability::MachineApplicable,
Applicability::HasPlaceholders,
);
}