about summary refs log tree commit diff
path: root/compiler/rustc_parse/src
diff options
context:
space:
mode:
authorJacob Pratt <jacob@jhpratt.dev>2025-04-11 21:21:01 +0200
committerGitHub <noreply@github.com>2025-04-11 21:21:01 +0200
commit2f873f96e2219aefe00a072cf1280001788fe7f3 (patch)
tree8ec21ca32e1ae966b4381ab8fcc831c697999353 /compiler/rustc_parse/src
parent00b9060c3be66b176e33065b81c500357ca8931c (diff)
parentd25c8a8ade05384e9ca84866be8672a97896826d (diff)
downloadrust-2f873f96e2219aefe00a072cf1280001788fe7f3.tar.gz
rust-2f873f96e2219aefe00a072cf1280001788fe7f3.zip
Rollup merge of #139653 - nnethercote:fix-139495, r=petrochenkov
Handle a negated literal in `eat_token_lit`.

Fixes #139495.

r? `@petrochenkov`
Diffstat (limited to 'compiler/rustc_parse/src')
-rw-r--r--compiler/rustc_parse/src/parser/expr.rs13
1 files changed, 9 insertions, 4 deletions
diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs
index 9c457f150a3..d52e36fcfac 100644
--- a/compiler/rustc_parse/src/parser/expr.rs
+++ b/compiler/rustc_parse/src/parser/expr.rs
@@ -2166,10 +2166,15 @@ impl<'a> Parser<'a> {
                 let expr = self
                     .eat_metavar_seq(mv_kind, |this| this.parse_expr())
                     .expect("metavar seq expr");
-                let ast::ExprKind::Lit(token_lit) = expr.kind else {
-                    panic!("didn't reparse an expr");
-                };
-                Some(token_lit)
+                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);
+                }
             }
             _ => None,
         }