about summary refs log tree commit diff
path: root/compiler
diff options
context:
space:
mode:
authorNicholas Nethercote <n.nethercote@gmail.com>2022-08-15 09:13:03 +1000
committerNicholas Nethercote <n.nethercote@gmail.com>2022-08-15 09:51:11 +1000
commit1e8497351d7cb15eddd9db2f88866294bab27a21 (patch)
treec0334d8e7425f0b5e9a399e956607007810406e9 /compiler
parente2b52ff73edc8b0b7c74bc28760d618187731fe8 (diff)
downloadrust-1e8497351d7cb15eddd9db2f88866294bab27a21.tar.gz
rust-1e8497351d7cb15eddd9db2f88866294bab27a21.zip
Streamline `parse_path_start_expr`.
Let-chaining avoids some code duplication.
Diffstat (limited to 'compiler')
-rw-r--r--compiler/rustc_parse/src/parser/expr.rs15
1 files changed, 6 insertions, 9 deletions
diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs
index 2880ef78c8d..ec6a64b745e 100644
--- a/compiler/rustc_parse/src/parser/expr.rs
+++ b/compiler/rustc_parse/src/parser/expr.rs
@@ -1510,34 +1510,31 @@ impl<'a> Parser<'a> {
         } else {
             (None, self.parse_path(PathStyle::Expr)?)
         };
-        let lo = path.span;
 
         // `!`, as an operator, is prefix, so we know this isn't that.
-        let (hi, kind) = if self.eat(&token::Not) {
+        let (span, kind) = if self.eat(&token::Not) {
             // MACRO INVOCATION expression
             if qself.is_some() {
                 self.struct_span_err(path.span, "macros cannot use qualified paths").emit();
             }
+            let lo = path.span;
             let mac = MacCall {
                 path,
                 args: self.parse_mac_args()?,
                 prior_type_ascription: self.last_type_ascription,
             };
-            (self.prev_token.span, ExprKind::MacCall(mac))
-        } else if self.check(&token::OpenDelim(Delimiter::Brace)) {
-            if let Some(expr) = self.maybe_parse_struct_expr(qself.as_ref(), &path, &attrs) {
+            (lo.to(self.prev_token.span), ExprKind::MacCall(mac))
+        } else if self.check(&token::OpenDelim(Delimiter::Brace)) &&
+            let Some(expr) = self.maybe_parse_struct_expr(qself.as_ref(), &path, &attrs) {
                 if qself.is_some() {
                     self.sess.gated_spans.gate(sym::more_qualified_paths, path.span);
                 }
                 return expr;
-            } else {
-                (path.span, ExprKind::Path(qself, path))
-            }
         } else {
             (path.span, ExprKind::Path(qself, path))
         };
 
-        let expr = self.mk_expr(lo.to(hi), kind, attrs);
+        let expr = self.mk_expr(span, kind, attrs);
         self.maybe_recover_from_bad_qpath(expr)
     }