about summary refs log tree commit diff
path: root/compiler/rustc_parse/src/parser
diff options
context:
space:
mode:
authorNicholas Nethercote <n.nethercote@gmail.com>2024-03-13 15:59:41 +1100
committerNicholas Nethercote <n.nethercote@gmail.com>2024-03-25 13:05:59 +1100
commit9c091160dc57aa5224a35e6755c357f7089ff2e5 (patch)
tree9c00dccf67e7434fadd42df7ff3e88dd3ee4e031 /compiler/rustc_parse/src/parser
parent90eeb3d6817303469059041ef7c8c57f3508f476 (diff)
downloadrust-9c091160dc57aa5224a35e6755c357f7089ff2e5.tar.gz
rust-9c091160dc57aa5224a35e6755c357f7089ff2e5.zip
Change `parse_expr_tuple_field_access`.
Pass in the span for the field rather than using `prev_token`.
Also rename it `mk_expr_tuple_field_access`, because it doesn't do any
actual parsing, it just creates an expression with what it's given.

Not much of a clarity win by itself, but unlocks additional subsequent
simplifications.
Diffstat (limited to 'compiler/rustc_parse/src/parser')
-rw-r--r--compiler/rustc_parse/src/parser/expr.rs25
1 files changed, 15 insertions, 10 deletions
diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs
index 50589ad3f12..f96e44eb0f7 100644
--- a/compiler/rustc_parse/src/parser/expr.rs
+++ b/compiler/rustc_parse/src/parser/expr.rs
@@ -1002,22 +1002,25 @@ impl<'a> Parser<'a> {
         match self.token.uninterpolate().kind {
             token::Ident(..) => self.parse_dot_suffix(base, lo),
             token::Literal(token::Lit { kind: token::Integer, symbol, suffix }) => {
+                let ident_span = self.token.span;
                 self.bump();
-                Ok(self.parse_expr_tuple_field_access(lo, base, symbol, suffix))
+                Ok(self.mk_expr_tuple_field_access(lo, ident_span, base, symbol, suffix))
             }
             token::Literal(token::Lit { kind: token::Float, symbol, suffix }) => {
                 Ok(match self.break_up_float(symbol, self.token.span) {
                     // 1e2
                     DestructuredFloat::Single(sym, _sp) => {
+                        let ident_span = self.token.span;
                         self.bump();
-                        self.parse_expr_tuple_field_access(lo, base, sym, suffix)
+                        self.mk_expr_tuple_field_access(lo, ident_span, base, sym, suffix)
                     }
                     // 1.
                     DestructuredFloat::TrailingDot(sym, ident_span, dot_span) => {
                         assert!(suffix.is_none());
                         self.token = Token::new(token::Ident(sym, IdentIsRaw::No), ident_span);
+                        let ident_span = self.token.span;
                         self.bump_with((Token::new(token::Dot, dot_span), self.token_spacing));
-                        self.parse_expr_tuple_field_access(lo, base, sym, None)
+                        self.mk_expr_tuple_field_access(lo, ident_span, base, sym, None)
                     }
                     // 1.2 | 1.2e3
                     DestructuredFloat::MiddleDot(
@@ -1030,13 +1033,16 @@ impl<'a> Parser<'a> {
                         self.token = Token::new(token::Ident(symbol1, IdentIsRaw::No), ident1_span);
                         // This needs to be `Spacing::Alone` to prevent regressions.
                         // See issue #76399 and PR #76285 for more details
+                        let ident_span = self.token.span;
                         self.bump_with((Token::new(token::Dot, dot_span), Spacing::Alone));
-                        let base1 = self.parse_expr_tuple_field_access(lo, base, symbol1, None);
+                        let base1 =
+                            self.mk_expr_tuple_field_access(lo, ident_span, base, symbol1, None);
                         let next_token2 =
                             Token::new(token::Ident(symbol2, IdentIsRaw::No), ident2_span);
                         self.bump_with((next_token2, self.token_spacing)); // `.`
+                        let ident_span = self.token.span;
                         self.bump();
-                        self.parse_expr_tuple_field_access(lo, base1, symbol2, suffix)
+                        self.mk_expr_tuple_field_access(lo, ident_span, base1, symbol2, suffix)
                     }
                     DestructuredFloat::Error => base,
                 })
@@ -1254,19 +1260,18 @@ impl<'a> Parser<'a> {
         Ok(fields.into_iter().collect())
     }
 
-    fn parse_expr_tuple_field_access(
+    fn mk_expr_tuple_field_access(
         &mut self,
         lo: Span,
+        ident_span: Span,
         base: P<Expr>,
         field: Symbol,
         suffix: Option<Symbol>,
     ) -> P<Expr> {
-        let span = self.prev_token.span;
-        let field = ExprKind::Field(base, Ident::new(field, span));
         if let Some(suffix) = suffix {
-            self.expect_no_tuple_index_suffix(span, suffix);
+            self.expect_no_tuple_index_suffix(ident_span, suffix);
         }
-        self.mk_expr(lo.to(span), field)
+        self.mk_expr(lo.to(ident_span), ExprKind::Field(base, Ident::new(field, ident_span)))
     }
 
     /// Parse a function call expression, `expr(...)`.