recover #[attr] if expr {}
This commit is contained in:
parent
c9e1f13f6e
commit
66470d3217
4 changed files with 54 additions and 8 deletions
|
@ -2,6 +2,7 @@
|
|||
|
||||
#![feature(bool_to_option)]
|
||||
#![feature(crate_visibility_modifier)]
|
||||
#![feature(slice_patterns)]
|
||||
|
||||
use syntax::ast;
|
||||
use syntax::print::pprust;
|
||||
|
|
|
@ -668,19 +668,20 @@ impl<'a> Parser<'a> {
|
|||
expr.map(|mut expr| {
|
||||
attrs.extend::<Vec<_>>(expr.attrs.into());
|
||||
expr.attrs = attrs;
|
||||
match expr.kind {
|
||||
ExprKind::If(..) if !expr.attrs.is_empty() => {
|
||||
// Just point to the first attribute in there...
|
||||
let span = expr.attrs[0].span;
|
||||
self.span_err(span, "attributes are not yet allowed on `if` expressions");
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
self.error_attr_on_if_expr(&expr);
|
||||
expr
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
fn error_attr_on_if_expr(&self, expr: &Expr) {
|
||||
if let (ExprKind::If(..), [a0, ..]) = (&expr.kind, &*expr.attrs) {
|
||||
// Just point to the first attribute in there...
|
||||
self.struct_span_err(a0.span, "attributes are not yet allowed on `if` expressions")
|
||||
.emit();
|
||||
}
|
||||
}
|
||||
|
||||
fn parse_dot_or_call_expr_with_(&mut self, e0: P<Expr>, lo: Span) -> PResult<'a, P<Expr>> {
|
||||
let mut e = e0;
|
||||
let mut hi;
|
||||
|
|
9
src/test/ui/parser/recovery-attr-on-if.rs
Normal file
9
src/test/ui/parser/recovery-attr-on-if.rs
Normal file
|
@ -0,0 +1,9 @@
|
|||
fn main() {
|
||||
#[attr] if true {};
|
||||
//~^ ERROR cannot find attribute
|
||||
//~| ERROR attributes are not yet allowed on `if` expressions
|
||||
#[attr] if true {};
|
||||
//~^ ERROR cannot find attribute
|
||||
//~| ERROR attributes are not yet allowed on `if` expressions
|
||||
let _recovery_witness: () = 0; //~ ERROR mismatched types
|
||||
}
|
35
src/test/ui/parser/recovery-attr-on-if.stderr
Normal file
35
src/test/ui/parser/recovery-attr-on-if.stderr
Normal file
|
@ -0,0 +1,35 @@
|
|||
error: attributes are not yet allowed on `if` expressions
|
||||
--> $DIR/recovery-attr-on-if.rs:2:5
|
||||
|
|
||||
LL | #[attr] if true {};
|
||||
| ^^^^^^^
|
||||
|
||||
error: attributes are not yet allowed on `if` expressions
|
||||
--> $DIR/recovery-attr-on-if.rs:5:5
|
||||
|
|
||||
LL | #[attr] if true {};
|
||||
| ^^^^^^^
|
||||
|
||||
error: cannot find attribute `attr` in this scope
|
||||
--> $DIR/recovery-attr-on-if.rs:5:7
|
||||
|
|
||||
LL | #[attr] if true {};
|
||||
| ^^^^
|
||||
|
||||
error: cannot find attribute `attr` in this scope
|
||||
--> $DIR/recovery-attr-on-if.rs:2:7
|
||||
|
|
||||
LL | #[attr] if true {};
|
||||
| ^^^^
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/recovery-attr-on-if.rs:8:33
|
||||
|
|
||||
LL | let _recovery_witness: () = 0;
|
||||
| -- ^ expected `()`, found integer
|
||||
| |
|
||||
| expected due to this
|
||||
|
||||
error: aborting due to 5 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0308`.
|
Loading…
Add table
Add a link
Reference in a new issue