mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-16 17:03:35 +00:00
Do not recover when parsing stmt in cfg-eval.
This commit is contained in:
parent
f2eb9f85b9
commit
d56ce8e199
@ -166,7 +166,9 @@ impl CfgEval<'_, '_> {
|
||||
))
|
||||
},
|
||||
Annotatable::Stmt(_) => |parser| {
|
||||
Ok(Annotatable::Stmt(P(parser.parse_stmt(ForceCollect::Yes)?.unwrap())))
|
||||
Ok(Annotatable::Stmt(P(parser
|
||||
.parse_stmt_without_recovery(false, ForceCollect::Yes)?
|
||||
.unwrap())))
|
||||
},
|
||||
Annotatable::Expr(_) => {
|
||||
|parser| Ok(Annotatable::Expr(parser.parse_expr_force_collect()?))
|
||||
|
@ -37,7 +37,8 @@ impl<'a> Parser<'a> {
|
||||
|
||||
/// If `force_collect` is [`ForceCollect::Yes`], forces collection of tokens regardless of whether
|
||||
/// or not we have attributes
|
||||
pub(crate) fn parse_stmt_without_recovery(
|
||||
// Public for `cfg_eval` macro expansion.
|
||||
pub fn parse_stmt_without_recovery(
|
||||
&mut self,
|
||||
capture_semi: bool,
|
||||
force_collect: ForceCollect,
|
||||
|
13
tests/ui/cfg/cfg-stmt-recovery.rs
Normal file
13
tests/ui/cfg/cfg-stmt-recovery.rs
Normal file
@ -0,0 +1,13 @@
|
||||
// Verify that we do not ICE when failing to parse a statement in `cfg_eval`.
|
||||
|
||||
#![feature(cfg_eval)]
|
||||
#![feature(stmt_expr_attributes)]
|
||||
|
||||
#[cfg_eval]
|
||||
fn main() {
|
||||
#[cfg_eval]
|
||||
let _ = #[cfg(FALSE)] 0;
|
||||
//~^ ERROR removing an expression is not supported in this position
|
||||
//~| ERROR expected expression, found `;`
|
||||
//~| ERROR removing an expression is not supported in this position
|
||||
}
|
20
tests/ui/cfg/cfg-stmt-recovery.stderr
Normal file
20
tests/ui/cfg/cfg-stmt-recovery.stderr
Normal file
@ -0,0 +1,20 @@
|
||||
error: removing an expression is not supported in this position
|
||||
--> $DIR/cfg-stmt-recovery.rs:9:13
|
||||
|
|
||||
LL | let _ = #[cfg(FALSE)] 0;
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
error: expected expression, found `;`
|
||||
--> $DIR/cfg-stmt-recovery.rs:9:28
|
||||
|
|
||||
LL | let _ = #[cfg(FALSE)] 0;
|
||||
| ^ expected expression
|
||||
|
||||
error: removing an expression is not supported in this position
|
||||
--> $DIR/cfg-stmt-recovery.rs:9:13
|
||||
|
|
||||
LL | let _ = #[cfg(FALSE)] 0;
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
Loading…
Reference in New Issue
Block a user