From 073010d425d7b6ff5e79fd41f209e4915daa6066 Mon Sep 17 00:00:00 2001 From: Noah Lev Date: Thu, 17 Feb 2022 14:58:46 -0800 Subject: Improve handling of `tmp` variable name conflicts --- compiler/rustc_parse/src/parser/diagnostics.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'compiler/rustc_parse/src/parser') diff --git a/compiler/rustc_parse/src/parser/diagnostics.rs b/compiler/rustc_parse/src/parser/diagnostics.rs index 26ca018685e..dcb150f18aa 100644 --- a/compiler/rustc_parse/src/parser/diagnostics.rs +++ b/compiler/rustc_parse/src/parser/diagnostics.rs @@ -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, ); } -- cgit 1.4.1-3-g733a5