about summary refs log tree commit diff
path: root/compiler/rustc_parse/src/parser/expr.rs
diff options
context:
space:
mode:
authorNicholas Nethercote <n.nethercote@gmail.com>2024-03-13 15:34:05 +1100
committerNicholas Nethercote <n.nethercote@gmail.com>2024-03-25 13:05:59 +1100
commit42066b029f3009518e2ba8c7bd20f5781b180b8f (patch)
treed38a915b53a7b7b8eac57dc6c2378e0ff55f495c /compiler/rustc_parse/src/parser/expr.rs
parent0824b300eb0dae5d9ed59719d3f2732016683d66 (diff)
downloadrust-42066b029f3009518e2ba8c7bd20f5781b180b8f.tar.gz
rust-42066b029f3009518e2ba8c7bd20f5781b180b8f.zip
Inline and remove `Parser::parse_expr_tuple_field_access_float`.
It has a single call site, and afterwards all the calls to
`parse_expr_tuple_field_access` are in a single method, which is nice.
Diffstat (limited to 'compiler/rustc_parse/src/parser/expr.rs')
-rw-r--r--compiler/rustc_parse/src/parser/expr.rs74
1 files changed, 38 insertions, 36 deletions
diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs
index fe17eba0d7b..cf7771f87a8 100644
--- a/compiler/rustc_parse/src/parser/expr.rs
+++ b/compiler/rustc_parse/src/parser/expr.rs
@@ -1005,7 +1005,44 @@ impl<'a> Parser<'a> {
                 Ok(self.parse_expr_tuple_field_access(lo, base, symbol, suffix, None))
             }
             token::Literal(token::Lit { kind: token::Float, symbol, suffix }) => {
-                Ok(self.parse_expr_tuple_field_access_float(lo, base, symbol, suffix))
+                Ok(match self.break_up_float(symbol, self.token.span) {
+                    // 1e2
+                    DestructuredFloat::Single(sym, _sp) => {
+                        self.parse_expr_tuple_field_access(lo, base, sym, suffix, None)
+                    }
+                    // 1.
+                    DestructuredFloat::TrailingDot(sym, ident_span, dot_span) => {
+                        assert!(suffix.is_none());
+                        self.token = Token::new(token::Ident(sym, IdentIsRaw::No), ident_span);
+                        let next_token = (Token::new(token::Dot, dot_span), self.token_spacing);
+                        self.parse_expr_tuple_field_access(lo, base, sym, None, Some(next_token))
+                    }
+                    // 1.2 | 1.2e3
+                    DestructuredFloat::MiddleDot(
+                        symbol1,
+                        ident1_span,
+                        dot_span,
+                        symbol2,
+                        ident2_span,
+                    ) => {
+                        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 next_token1 = (Token::new(token::Dot, dot_span), Spacing::Alone);
+                        let base1 = self.parse_expr_tuple_field_access(
+                            lo,
+                            base,
+                            symbol1,
+                            None,
+                            Some(next_token1),
+                        );
+                        let next_token2 =
+                            Token::new(token::Ident(symbol2, IdentIsRaw::No), ident2_span);
+                        self.bump_with((next_token2, self.token_spacing)); // `.`
+                        self.parse_expr_tuple_field_access(lo, base1, symbol2, suffix, None)
+                    }
+                    DestructuredFloat::Error => base,
+                })
             }
             _ => {
                 self.error_unexpected_after_dot();
@@ -1119,41 +1156,6 @@ impl<'a> Parser<'a> {
         }
     }
 
-    fn parse_expr_tuple_field_access_float(
-        &mut self,
-        lo: Span,
-        base: P<Expr>,
-        float: Symbol,
-        suffix: Option<Symbol>,
-    ) -> P<Expr> {
-        match self.break_up_float(float, self.token.span) {
-            // 1e2
-            DestructuredFloat::Single(sym, _sp) => {
-                self.parse_expr_tuple_field_access(lo, base, sym, suffix, None)
-            }
-            // 1.
-            DestructuredFloat::TrailingDot(sym, ident_span, dot_span) => {
-                assert!(suffix.is_none());
-                self.token = Token::new(token::Ident(sym, IdentIsRaw::No), ident_span);
-                let next_token = (Token::new(token::Dot, dot_span), self.token_spacing);
-                self.parse_expr_tuple_field_access(lo, base, sym, None, Some(next_token))
-            }
-            // 1.2 | 1.2e3
-            DestructuredFloat::MiddleDot(symbol1, ident1_span, dot_span, symbol2, ident2_span) => {
-                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 next_token1 = (Token::new(token::Dot, dot_span), Spacing::Alone);
-                let base1 =
-                    self.parse_expr_tuple_field_access(lo, base, symbol1, None, Some(next_token1));
-                let next_token2 = Token::new(token::Ident(symbol2, IdentIsRaw::No), ident2_span);
-                self.bump_with((next_token2, self.token_spacing)); // `.`
-                self.parse_expr_tuple_field_access(lo, base1, symbol2, suffix, None)
-            }
-            DestructuredFloat::Error => base,
-        }
-    }
-
     /// Parse the field access used in offset_of, matched by `$(e:expr)+`.
     /// Currently returns a list of idents. However, it should be possible in
     /// future to also do array indices, which might be arbitrary expressions.