This repository was archived by the owner on May 28, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +38
-2
lines changed
Expand file tree Collapse file tree 4 files changed +38
-2
lines changed Original file line number Diff line number Diff line change @@ -166,7 +166,9 @@ impl CfgEval<'_, '_> {
166166 ) )
167167 } ,
168168 Annotatable :: Stmt ( _) => |parser| {
169- Ok ( Annotatable :: Stmt ( P ( parser. parse_stmt ( ForceCollect :: Yes ) ?. unwrap ( ) ) ) )
169+ Ok ( Annotatable :: Stmt ( P ( parser
170+ . parse_stmt_without_recovery ( false , ForceCollect :: Yes ) ?
171+ . unwrap ( ) ) ) )
170172 } ,
171173 Annotatable :: Expr ( _) => {
172174 |parser| Ok ( Annotatable :: Expr ( parser. parse_expr_force_collect ( ) ?) )
Original file line number Diff line number Diff line change @@ -37,7 +37,8 @@ impl<'a> Parser<'a> {
3737
3838 /// If `force_collect` is [`ForceCollect::Yes`], forces collection of tokens regardless of whether
3939 /// or not we have attributes
40- pub ( crate ) fn parse_stmt_without_recovery (
40+ // Public for `cfg_eval` macro expansion.
41+ pub fn parse_stmt_without_recovery (
4142 & mut self ,
4243 capture_semi : bool ,
4344 force_collect : ForceCollect ,
Original file line number Diff line number Diff line change 1+ // Verify that we do not ICE when failing to parse a statement in `cfg_eval`.
2+
3+ #![ feature( cfg_eval) ]
4+ #![ feature( stmt_expr_attributes) ]
5+
6+ #[ cfg_eval]
7+ fn main ( ) {
8+ #[ cfg_eval]
9+ let _ = #[ cfg ( FALSE ) ] 0 ;
10+ //~^ ERROR removing an expression is not supported in this position
11+ //~| ERROR expected expression, found `;`
12+ //~| ERROR removing an expression is not supported in this position
13+ }
Original file line number Diff line number Diff line change 1+ error: removing an expression is not supported in this position
2+ --> $DIR/cfg-stmt-recovery.rs:9:13
3+ |
4+ LL | let _ = #[cfg(FALSE)] 0;
5+ | ^^^^^^^^^^^^^
6+
7+ error: expected expression, found `;`
8+ --> $DIR/cfg-stmt-recovery.rs:9:28
9+ |
10+ LL | let _ = #[cfg(FALSE)] 0;
11+ | ^ expected expression
12+
13+ error: removing an expression is not supported in this position
14+ --> $DIR/cfg-stmt-recovery.rs:9:13
15+ |
16+ LL | let _ = #[cfg(FALSE)] 0;
17+ | ^^^^^^^^^^^^^
18+
19+ error: aborting due to 3 previous errors
20+
You can’t perform that action at this time.
0 commit comments