This repository was archived by the owner on May 28, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +29
-4
lines changed
compiler/rustc_parse/src/parser Expand file tree Collapse file tree 3 files changed +29
-4
lines changed Original file line number Diff line number Diff line change @@ -2166,10 +2166,15 @@ impl<'a> Parser<'a> {
2166
2166
let expr = self
2167
2167
. eat_metavar_seq ( mv_kind, |this| this. parse_expr ( ) )
2168
2168
. expect ( "metavar seq expr" ) ;
2169
- let ast:: ExprKind :: Lit ( token_lit) = expr. kind else {
2170
- panic ! ( "didn't reparse an expr" ) ;
2171
- } ;
2172
- Some ( token_lit)
2169
+ if let ast:: ExprKind :: Lit ( token_lit) = expr. kind {
2170
+ Some ( token_lit)
2171
+ } else if let ast:: ExprKind :: Unary ( UnOp :: Neg , inner) = & expr. kind
2172
+ && let ast:: Expr { kind : ast:: ExprKind :: Lit ( _) , .. } = * * inner
2173
+ {
2174
+ None
2175
+ } else {
2176
+ panic ! ( "unexpected reparsed expr: {:?}" , expr. kind) ;
2177
+ }
2173
2178
}
2174
2179
_ => None ,
2175
2180
}
Original file line number Diff line number Diff line change
1
+ macro_rules! m {
2
+ ( $abi : expr) => { extern $abi } //~ ERROR expected expression, found keyword `extern`
3
+ }
4
+
5
+ fn main ( ) {
6
+ m ! ( -2 )
7
+ }
Original file line number Diff line number Diff line change
1
+ error: expected expression, found keyword `extern`
2
+ --> $DIR/reparse-expr-issue-139495.rs:2:22
3
+ |
4
+ LL | ($abi : expr) => { extern $abi }
5
+ | ^^^^^^ expected expression
6
+ ...
7
+ LL | m!(-2)
8
+ | ------ in this macro invocation
9
+ |
10
+ = note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info)
11
+
12
+ error: aborting due to 1 previous error
13
+
You can’t perform that action at this time.
0 commit comments