diff options
Diffstat (limited to 'compiler/rustc_parse/src')
| -rw-r--r-- | compiler/rustc_parse/src/lib.rs | 25 | ||||
| -rw-r--r-- | compiler/rustc_parse/src/parser/nonterminal.rs | 17 | ||||
| -rw-r--r-- | compiler/rustc_parse/src/parser/stmt.rs | 20 | ||||
| -rw-r--r-- | compiler/rustc_parse/src/validate_attr.rs | 17 |
4 files changed, 38 insertions, 41 deletions
diff --git a/compiler/rustc_parse/src/lib.rs b/compiler/rustc_parse/src/lib.rs index 07f972c2fa8..73e05a35277 100644 --- a/compiler/rustc_parse/src/lib.rs +++ b/compiler/rustc_parse/src/lib.rs @@ -2,8 +2,10 @@ #![feature(array_windows)] #![feature(crate_visibility_modifier)] +#![feature(if_let_guard)] #![cfg_attr(bootstrap, feature(bindings_after_at))] #![feature(box_patterns)] +#![cfg_attr(bootstrap, allow(incomplete_features))] // if_let_guard #![recursion_limit = "256"] use rustc_ast as ast; @@ -262,20 +264,17 @@ pub fn nt_to_tokenstream( let tokens = match *nt { Nonterminal::NtItem(ref item) => prepend_attrs(&item.attrs, item.tokens.as_ref()), Nonterminal::NtBlock(ref block) => convert_tokens(block.tokens.as_ref()), - Nonterminal::NtStmt(ref stmt) => { - if let ast::StmtKind::Empty = stmt.kind { - let tokens = AttrAnnotatedTokenStream::new(vec![( - tokenstream::AttrAnnotatedTokenTree::Token(Token::new( - TokenKind::Semi, - stmt.span, - )), - Spacing::Alone, - )]); - prepend_attrs(&stmt.attrs(), Some(&LazyTokenStream::new(tokens))) - } else { - prepend_attrs(&stmt.attrs(), stmt.tokens()) - } + Nonterminal::NtStmt(ref stmt) if let ast::StmtKind::Empty = stmt.kind => { + let tokens = AttrAnnotatedTokenStream::new(vec![( + tokenstream::AttrAnnotatedTokenTree::Token(Token::new( + TokenKind::Semi, + stmt.span, + )), + Spacing::Alone, + )]); + prepend_attrs(&stmt.attrs(), Some(&LazyTokenStream::new(tokens))) } + Nonterminal::NtStmt(ref stmt) => prepend_attrs(&stmt.attrs(), stmt.tokens()), Nonterminal::NtPat(ref pat) => convert_tokens(pat.tokens.as_ref()), Nonterminal::NtTy(ref ty) => convert_tokens(ty.tokens.as_ref()), Nonterminal::NtIdent(ident, is_raw) => { diff --git a/compiler/rustc_parse/src/parser/nonterminal.rs b/compiler/rustc_parse/src/parser/nonterminal.rs index 313d9db58fc..72e6f8a1bc8 100644 --- a/compiler/rustc_parse/src/parser/nonterminal.rs +++ b/compiler/rustc_parse/src/parser/nonterminal.rs @@ -143,15 +143,16 @@ impl<'a> Parser<'a> { token::NtTy(self.collect_tokens_no_attrs(|this| this.parse_ty())?) } // this could be handled like a token, since it is one + NonterminalKind::Ident + if let Some((ident, is_raw)) = get_macro_ident(&self.token) => + { + self.bump(); + token::NtIdent(ident, is_raw) + } NonterminalKind::Ident => { - if let Some((ident, is_raw)) = get_macro_ident(&self.token) { - self.bump(); - token::NtIdent(ident, is_raw) - } else { - let token_str = pprust::token_to_string(&self.token); - let msg = &format!("expected ident, found {}", &token_str); - return Err(self.struct_span_err(self.token.span, msg)); - } + let token_str = pprust::token_to_string(&self.token); + let msg = &format!("expected ident, found {}", &token_str); + return Err(self.struct_span_err(self.token.span, msg)); } NonterminalKind::Path => token::NtPath( self.collect_tokens_no_attrs(|this| this.parse_path(PathStyle::Type))?, diff --git a/compiler/rustc_parse/src/parser/stmt.rs b/compiler/rustc_parse/src/parser/stmt.rs index 9ef3f61ec34..85515bd2a63 100644 --- a/compiler/rustc_parse/src/parser/stmt.rs +++ b/compiler/rustc_parse/src/parser/stmt.rs @@ -493,21 +493,19 @@ impl<'a> Parser<'a> { } } StmtKind::Expr(_) | StmtKind::MacCall(_) => {} - StmtKind::Local(ref mut local) => { - if let Err(e) = self.expect_semi() { - // We might be at the `,` in `let x = foo<bar, baz>;`. Try to recover. - match &mut local.init { - Some(ref mut expr) => { - self.check_mistyped_turbofish_with_multiple_type_params(e, expr)?; - // We found `foo<bar, baz>`, have we fully recovered? - self.expect_semi()?; - } - None => return Err(e), + StmtKind::Local(ref mut local) if let Err(e) = self.expect_semi() => { + // We might be at the `,` in `let x = foo<bar, baz>;`. Try to recover. + match &mut local.init { + Some(ref mut expr) => { + self.check_mistyped_turbofish_with_multiple_type_params(e, expr)?; + // We found `foo<bar, baz>`, have we fully recovered? + self.expect_semi()?; } + None => return Err(e), } eat_semi = false; } - StmtKind::Empty | StmtKind::Item(_) | StmtKind::Semi(_) => eat_semi = false, + StmtKind::Empty | StmtKind::Item(_) | StmtKind::Local(_) | StmtKind::Semi(_) => eat_semi = false, } if eat_semi && self.eat(&token::Semi) { diff --git a/compiler/rustc_parse/src/validate_attr.rs b/compiler/rustc_parse/src/validate_attr.rs index 21372725a68..67695dc2850 100644 --- a/compiler/rustc_parse/src/validate_attr.rs +++ b/compiler/rustc_parse/src/validate_attr.rs @@ -24,16 +24,15 @@ pub fn check_meta(sess: &ParseSess, attr: &Attribute) { Some((name, _, template, _)) if name != sym::rustc_dummy => { check_builtin_attribute(sess, attr, name, template) } - _ => { - if let MacArgs::Eq(..) = attr.get_normal_item().args { - // All key-value attributes are restricted to meta-item syntax. - parse_meta(sess, attr) - .map_err(|mut err| { - err.emit(); - }) - .ok(); - } + _ if let MacArgs::Eq(..) = attr.get_normal_item().args => { + // All key-value attributes are restricted to meta-item syntax. + parse_meta(sess, attr) + .map_err(|mut err| { + err.emit(); + }) + .ok(); } + _ => {} } } |
