about summary refs log tree commit diff
path: root/compiler/rustc_parse/src
diff options
context:
space:
mode:
authorNoah Lev <camelidcamel@gmail.com>2022-02-15 20:05:24 -0800
committerNoah Lev <camelidcamel@gmail.com>2022-03-23 22:31:57 -0700
commit80e57e223e98f7075cc4af83fa0eef948493d0df (patch)
treebe18bf695900dcb19680fd9235b98a12913e4eda /compiler/rustc_parse/src
parentd915606d50c273b084bf71bff1f31e347f0ccdee (diff)
downloadrust-80e57e223e98f7075cc4af83fa0eef948493d0df.tar.gz
rust-80e57e223e98f7075cc4af83fa0eef948493d0df.zip
Reduce rightward drift
Diffstat (limited to 'compiler/rustc_parse/src')
-rw-r--r--compiler/rustc_parse/src/parser/diagnostics.rs61
1 files changed, 30 insertions, 31 deletions
diff --git a/compiler/rustc_parse/src/parser/diagnostics.rs b/compiler/rustc_parse/src/parser/diagnostics.rs
index b29ea808d32..89cb1c89f81 100644
--- a/compiler/rustc_parse/src/parser/diagnostics.rs
+++ b/compiler/rustc_parse/src/parser/diagnostics.rs
@@ -1255,41 +1255,40 @@ impl<'a> Parser<'a> {
         );
         err.span_label(op_span, &format!("not a valid {} operator", kind.fixity));
 
-        if let ExprKind::Path(_, path) = &base.kind {
-            if let [segment] = path.segments.as_slice() {
-                let ident = segment.ident;
-                // (pre, post)
-                let spans = match kind.fixity {
-                    UnaryFixity::Pre => (op_span, ident.span.shrink_to_hi()),
-                    UnaryFixity::Post => (ident.span.shrink_to_lo(), op_span),
-                };
+        let help_base_case = |mut err: DiagnosticBuilder<'_>, base| {
+            err.help(&format!("use `{}= 1` instead", kind.op.chr()));
+            err.emit();
+            Ok(base)
+        };
 
-                if !ident.is_reserved() {
-                    if kind.standalone {
-                        return self.inc_dec_standalone_recovery(base, err, kind, ident, spans);
-                    } else {
-                        match kind.fixity {
-                            UnaryFixity::Pre => {
-                                return self.prefix_inc_dec_suggest_and_recover(
-                                    base, err, kind, ident, spans,
-                                );
-                            }
-                            UnaryFixity::Post => {
-                                return self.postfix_inc_dec_suggest_and_recover(
-                                    base, err, kind, ident, spans,
-                                );
-                            }
-                        }
-                    }
+        let ExprKind::Path(_, path) = &base.kind
+            else { return help_base_case(err, base) };
+        let [segment] = path.segments.as_slice()
+            else { return help_base_case(err, base) };
+        let ident = segment.ident;
+
+        // (pre, post)
+        let spans = match kind.fixity {
+            UnaryFixity::Pre => (op_span, ident.span.shrink_to_hi()),
+            UnaryFixity::Post => (ident.span.shrink_to_lo(), op_span),
+        };
+
+        if ident.is_reserved() {
+            return help_base_case(err, base);
+        }
+
+        if kind.standalone {
+            self.inc_dec_standalone_recovery(base, err, kind, ident, spans)
+        } else {
+            match kind.fixity {
+                UnaryFixity::Pre => {
+                    self.prefix_inc_dec_suggest_and_recover(base, err, kind, ident, spans)
+                }
+                UnaryFixity::Post => {
+                    self.postfix_inc_dec_suggest_and_recover(base, err, kind, ident, spans)
                 }
             }
         }
-
-        // base case
-        err.help(&format!("use `{}= 1` instead", kind.op.chr()));
-        err.emit();
-
-        Ok(base)
     }
 
     fn prefix_inc_dec_suggest_and_recover(