Properly emit expected ;
on #[attr] expr
This commit is contained in:
parent
829308e9af
commit
1658ca082a
@ -800,9 +800,8 @@ impl<'a> Parser<'a> {
|
||||
{
|
||||
Ok(next_attr) => next_attr,
|
||||
Err(inner_err) => {
|
||||
err.cancel();
|
||||
inner_err.cancel();
|
||||
return self.dcx().span_delayed_bug(expr.span, "not a tail expression");
|
||||
return err.emit();
|
||||
}
|
||||
}
|
||||
&& let ast::AttrKind::Normal(next_attr_kind) = next_attr.kind
|
||||
@ -813,9 +812,8 @@ impl<'a> Parser<'a> {
|
||||
let next_expr = match snapshot.parse_expr() {
|
||||
Ok(next_expr) => next_expr,
|
||||
Err(inner_err) => {
|
||||
err.cancel();
|
||||
inner_err.cancel();
|
||||
return self.dcx().span_delayed_bug(expr.span, "not a tail expression");
|
||||
return err.emit();
|
||||
}
|
||||
};
|
||||
// We have for sure
|
||||
|
@ -1,5 +1,5 @@
|
||||
error: expected `;`, found `#`
|
||||
--> $DIR/properly-recover-from-trailing-outer-attribute-in-body.rs:4:47
|
||||
--> $DIR/properly-recover-from-trailing-outer-attribute-in-body-1.rs:4:47
|
||||
|
|
||||
LL | #[cfg(feature = )]
|
||||
| ------------------ only `;` terminated statements or tail expressions are allowed after this attribute
|
||||
@ -18,7 +18,7 @@ LL | { [1, 2, 3].iter().map().collect::<String>() }
|
||||
| + +
|
||||
|
||||
error: expected statement after outer attribute
|
||||
--> $DIR/properly-recover-from-trailing-outer-attribute-in-body.rs:5:5
|
||||
--> $DIR/properly-recover-from-trailing-outer-attribute-in-body-1.rs:5:5
|
||||
|
|
||||
LL | #[attr]
|
||||
| ^^^^^^^
|
@ -0,0 +1,15 @@
|
||||
// Issue #121647: recovery path leaving unemitted error behind
|
||||
|
||||
macro_rules! the_macro {
|
||||
( $foo:stmt ; $bar:stmt ; ) => {
|
||||
#[cfg()]
|
||||
$foo //~ ERROR expected `;`, found `#`
|
||||
|
||||
#[cfg(bar)]
|
||||
$bar
|
||||
};
|
||||
}
|
||||
|
||||
fn main() {
|
||||
the_macro!( (); (); );
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
error: expected `;`, found `#`
|
||||
--> $DIR/properly-recover-from-trailing-outer-attribute-in-body-2.rs:6:13
|
||||
|
|
||||
LL | #[cfg()]
|
||||
| -------- only `;` terminated statements or tail expressions are allowed after this attribute
|
||||
LL | $foo
|
||||
| ^ expected `;` here
|
||||
LL |
|
||||
LL | #[cfg(bar)]
|
||||
| - unexpected token
|
||||
...
|
||||
LL | the_macro!( (); (); );
|
||||
| --------------------- in this macro invocation
|
||||
|
|
||||
= note: this error originates in the macro `the_macro` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
help: add `;` here
|
||||
|
|
||||
LL | $foo;
|
||||
| +
|
||||
help: alternatively, consider surrounding the expression with a block
|
||||
|
|
||||
LL | the_macro!( { () }; (); );
|
||||
| + +
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
|
Loading…
x
Reference in New Issue
Block a user