diff options
| author | Mazdak Farrokhzad <twingoow@gmail.com> | 2019-12-04 08:10:41 +0100 |
|---|---|---|
| committer | Mazdak Farrokhzad <twingoow@gmail.com> | 2019-12-20 22:53:40 +0100 |
| commit | 66470d3217f27b5950c38a3af4a99e0ef12fa2c8 (patch) | |
| tree | 423921e10f1a61276c526800ce6e88f12edb39a1 /src/librustc_parse | |
| parent | c9e1f13f6eb9d21224c083eb07d894adffc7ec96 (diff) | |
| download | rust-66470d3217f27b5950c38a3af4a99e0ef12fa2c8.tar.gz rust-66470d3217f27b5950c38a3af4a99e0ef12fa2c8.zip | |
recover `#[attr] if expr {}`
Diffstat (limited to 'src/librustc_parse')
| -rw-r--r-- | src/librustc_parse/lib.rs | 1 | ||||
| -rw-r--r-- | src/librustc_parse/parser/expr.rs | 17 |
2 files changed, 10 insertions, 8 deletions
diff --git a/src/librustc_parse/lib.rs b/src/librustc_parse/lib.rs index 58c36524380..3de7f888724 100644 --- a/src/librustc_parse/lib.rs +++ b/src/librustc_parse/lib.rs @@ -2,6 +2,7 @@ #![feature(bool_to_option)] #![feature(crate_visibility_modifier)] +#![feature(slice_patterns)] use syntax::ast; use syntax::print::pprust; diff --git a/src/librustc_parse/parser/expr.rs b/src/librustc_parse/parser/expr.rs index 7afa3d665d6..68af34a36bb 100644 --- a/src/librustc_parse/parser/expr.rs +++ b/src/librustc_parse/parser/expr.rs @@ -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; |
