diff options
| author | bors <bors@rust-lang.org> | 2025-04-22 22:09:56 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2025-04-22 22:09:56 +0000 |
| commit | 1a5bf12f6586d724ed5ff40e58e06c0233560c0e (patch) | |
| tree | 743381fa1a37fe8658b43b0a7ff79834d9a9181c /compiler/rustc_parse/src | |
| parent | 6bc57c6bf7d0024ad9ea5a2c112f3fc9c383c8a4 (diff) | |
| parent | 2d8264fb081cb76589bd226b8cc5e73c4599ab71 (diff) | |
| download | rust-1a5bf12f6586d724ed5ff40e58e06c0233560c0e.tar.gz rust-1a5bf12f6586d724ed5ff40e58e06c0233560c0e.zip | |
Auto merge of #140165 - ChrisDenton:rollup-on2dpr5, r=ChrisDenton
Rollup of 8 pull requests Successful merges: - #139617 (Use posix_spawn on cygwin) - #139921 (improve diagnostic for raw pointer field access with ->) - #140031 (compiletest: Fix deadline bugs in new executor) - #140072 (handle function alignment in miri) - #140104 (Fix auto diff failing on inherent impl blocks) - #140124 (Update books) - #140144 (Handle another negated literal in `eat_token_lit`.) - #140149 (test_nan: ensure the NAN contant is quiet) r? `@ghost` `@rustbot` modify labels: rollup
Diffstat (limited to 'compiler/rustc_parse/src')
| -rw-r--r-- | compiler/rustc_parse/src/parser/expr.rs | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs index f3ed798eba4..370eb3f402d 100644 --- a/compiler/rustc_parse/src/parser/expr.rs +++ b/compiler/rustc_parse/src/parser/expr.rs @@ -2146,6 +2146,17 @@ impl<'a> Parser<'a> { /// Keep this in sync with `Token::can_begin_literal_maybe_minus` and /// `Lit::from_token` (excluding unary negation). fn eat_token_lit(&mut self) -> Option<token::Lit> { + let check_expr = |expr: P<Expr>| { + if let ast::ExprKind::Lit(token_lit) = expr.kind { + Some(token_lit) + } else if let ast::ExprKind::Unary(UnOp::Neg, inner) = &expr.kind + && let ast::Expr { kind: ast::ExprKind::Lit(_), .. } = **inner + { + None + } else { + panic!("unexpected reparsed expr/literal: {:?}", expr.kind); + } + }; match self.token.uninterpolate().kind { token::Ident(name, IdentIsRaw::No) if name.is_bool_lit() => { self.bump(); @@ -2159,10 +2170,7 @@ impl<'a> Parser<'a> { let lit = self .eat_metavar_seq(MetaVarKind::Literal, |this| this.parse_literal_maybe_minus()) .expect("metavar seq literal"); - let ast::ExprKind::Lit(token_lit) = lit.kind else { - panic!("didn't reparse a literal"); - }; - Some(token_lit) + check_expr(lit) } token::OpenInvisible(InvisibleOrigin::MetaVar( mv_kind @ MetaVarKind::Expr { can_begin_literal_maybe_minus: true, .. }, @@ -2170,15 +2178,7 @@ impl<'a> Parser<'a> { let expr = self .eat_metavar_seq(mv_kind, |this| this.parse_expr()) .expect("metavar seq expr"); - if let ast::ExprKind::Lit(token_lit) = expr.kind { - Some(token_lit) - } else if let ast::ExprKind::Unary(UnOp::Neg, inner) = &expr.kind - && let ast::Expr { kind: ast::ExprKind::Lit(_), .. } = **inner - { - None - } else { - panic!("unexpected reparsed expr: {:?}", expr.kind); - } + check_expr(expr) } _ => None, } |
