diff options
| author | bors <bors@rust-lang.org> | 2019-12-21 11:05:03 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2019-12-21 11:05:03 +0000 |
| commit | c64eecf4d0907095928fb36fd3a1dd5fb2d9ff06 (patch) | |
| tree | 073a8038727414aed13f54622fce43ca63990ca6 /src/librustc_parse/parser/attr.rs | |
| parent | 9ff30a7810c586819a78188c173a7b74adbb9730 (diff) | |
| parent | 621661f8a63f2118f3add5c3d686d9a2b6f62e5e (diff) | |
| download | rust-c64eecf4d0907095928fb36fd3a1dd5fb2d9ff06.tar.gz rust-c64eecf4d0907095928fb36fd3a1dd5fb2d9ff06.zip | |
Auto merge of #66994 - Centril:stmt-polish, r=estebank
refactor expr & stmt parsing + improve recovery
Summary of important changes (best read commit-by-commit, ignoring whitespace changes):
- `AttrVec` is introduces as an alias for `ThinVec<Attribute>`
- `parse_expr_bottom` and `parse_stmt` are thoroughly refactored.
- Extract diagnostics logic for `vec![...]` in a pattern context.
- Recovery is added for `do catch { ... }`
- Recovery is added for `'label: non_block_expr`
- Recovery is added for `var $local`, `auto $local`, and `mut $local`. Fixes #65257.
- Recovery is added for `e1 and e2` and `e1 or e2`.
- ~~`macro_legacy_warnings` is turned into an error (has been a warning for 3 years!)~~
- Fixes #63396 by forward-porting #64105 which now works thanks to added recovery.
- `ui-fulldeps/ast_stmt_expr_attr.rs` is turned into UI and pretty tests.
- Recovery is fixed for `#[attr] if expr {}`
r? @estebank
Diffstat (limited to 'src/librustc_parse/parser/attr.rs')
| -rw-r--r-- | src/librustc_parse/parser/attr.rs | 23 |
1 files changed, 7 insertions, 16 deletions
diff --git a/src/librustc_parse/parser/attr.rs b/src/librustc_parse/parser/attr.rs index 00fd6b8a25b..51310fb88f6 100644 --- a/src/librustc_parse/parser/attr.rs +++ b/src/librustc_parse/parser/attr.rs @@ -1,4 +1,4 @@ -use super::{SeqSep, Parser, TokenType, PathStyle}; +use super::{Parser, TokenType, PathStyle}; use rustc_errors::PResult; use syntax::attr; use syntax::ast; @@ -301,8 +301,10 @@ impl<'a> Parser<'a> { crate fn parse_meta_item_kind(&mut self) -> PResult<'a, ast::MetaItemKind> { Ok(if self.eat(&token::Eq) { ast::MetaItemKind::NameValue(self.parse_unsuffixed_lit()?) - } else if self.eat(&token::OpenDelim(token::Paren)) { - ast::MetaItemKind::List(self.parse_meta_seq()?) + } else if self.check(&token::OpenDelim(token::Paren)) { + // Matches `meta_seq = ( COMMASEP(meta_item_inner) )`. + let (list, _) = self.parse_paren_comma_seq(|p| p.parse_meta_item_inner())?; + ast::MetaItemKind::List(list) } else { ast::MetaItemKind::Word }) @@ -311,16 +313,12 @@ impl<'a> Parser<'a> { /// Matches `meta_item_inner : (meta_item | UNSUFFIXED_LIT) ;`. fn parse_meta_item_inner(&mut self) -> PResult<'a, ast::NestedMetaItem> { match self.parse_unsuffixed_lit() { - Ok(lit) => { - return Ok(ast::NestedMetaItem::Literal(lit)) - } + Ok(lit) => return Ok(ast::NestedMetaItem::Literal(lit)), Err(ref mut err) => err.cancel(), } match self.parse_meta_item() { - Ok(mi) => { - return Ok(ast::NestedMetaItem::MetaItem(mi)) - } + Ok(mi) => return Ok(ast::NestedMetaItem::MetaItem(mi)), Err(ref mut err) => err.cancel(), } @@ -328,11 +326,4 @@ impl<'a> Parser<'a> { let msg = format!("expected unsuffixed literal or identifier, found `{}`", found); Err(self.diagnostic().struct_span_err(self.token.span, &msg)) } - - /// Matches `meta_seq = ( COMMASEP(meta_item_inner) )`. - fn parse_meta_seq(&mut self) -> PResult<'a, Vec<ast::NestedMetaItem>> { - self.parse_seq_to_end(&token::CloseDelim(token::Paren), - SeqSep::trailing_allowed(token::Comma), - |p: &mut Parser<'a>| p.parse_meta_item_inner()) - } } |
