about summary refs log tree commit diff
path: root/compiler/rustc_parse/src/parser
diff options
context:
space:
mode:
authorKevin Per <kevin.per@protonmail.com>2022-10-11 16:17:59 +0000
committerKevin Per <kevin.per@protonmail.com>2022-10-20 08:25:31 +0000
commit28d0312b7d47b8bc8fcb4888ca627231715db3cd (patch)
treea97b118b19593206ce32ee95aa57c5ab53ae00b4 /compiler/rustc_parse/src/parser
parent4b8f4319954ff2642690b9e5cbe4af352d095bf6 (diff)
downloadrust-28d0312b7d47b8bc8fcb4888ca627231715db3cd.tar.gz
rust-28d0312b7d47b8bc8fcb4888ca627231715db3cd.zip
Implement assertions and fixes to not emit empty spans without suggestions
Diffstat (limited to 'compiler/rustc_parse/src/parser')
-rw-r--r--compiler/rustc_parse/src/parser/diagnostics.rs10
1 files changed, 9 insertions, 1 deletions
diff --git a/compiler/rustc_parse/src/parser/diagnostics.rs b/compiler/rustc_parse/src/parser/diagnostics.rs
index 828b7d2f2f7..7e11ca57ceb 100644
--- a/compiler/rustc_parse/src/parser/diagnostics.rs
+++ b/compiler/rustc_parse/src/parser/diagnostics.rs
@@ -1374,9 +1374,17 @@ impl<'a> Parser<'a> {
         kind: IncDecRecovery,
         (pre_span, post_span): (Span, Span),
     ) -> MultiSugg {
+        let mut patches = Vec::new();
+
+        if !pre_span.is_empty() {
+            patches.push((pre_span, String::new()));
+        }
+
+        patches.push((post_span, format!(" {}= 1", kind.op.chr())));
+
         MultiSugg {
             msg: format!("use `{}= 1` instead", kind.op.chr()),
-            patches: vec![(pre_span, String::new()), (post_span, format!(" {}= 1", kind.op.chr()))],
+            patches,
             applicability: Applicability::MachineApplicable,
         }
     }