diff options
| author | Mazdak Farrokhzad <twingoow@gmail.com> | 2020-01-31 12:31:51 +0100 |
|---|---|---|
| committer | Mazdak Farrokhzad <twingoow@gmail.com> | 2020-02-13 15:16:36 +0100 |
| commit | fd64b3bcdfcc844b9b25318106917937f7b17b94 (patch) | |
| tree | ab41c0547a96d484fb4279dd09f3a3e8e7d1b8ae /src/librustc_parse/parser | |
| parent | c2026030b5d761a83d62c7e198057b119addcfd1 (diff) | |
| download | rust-fd64b3bcdfcc844b9b25318106917937f7b17b94.tar.gz rust-fd64b3bcdfcc844b9b25318106917937f7b17b94.zip | |
parser: make `eat_macro_def` redundant.
Diffstat (limited to 'src/librustc_parse/parser')
| -rw-r--r-- | src/librustc_parse/parser/item.rs | 35 | ||||
| -rw-r--r-- | src/librustc_parse/parser/stmt.rs | 10 |
2 files changed, 12 insertions, 33 deletions
diff --git a/src/librustc_parse/parser/item.rs b/src/librustc_parse/parser/item.rs index 745d125b58c..27b3d501751 100644 --- a/src/librustc_parse/parser/item.rs +++ b/src/librustc_parse/parser/item.rs @@ -86,7 +86,7 @@ impl<'a> Parser<'a> { let vis = self.parse_visibility(FollowedByType::No)?; if let Some((ident, kind)) = self.parse_item_kind(&mut attrs, macros_allowed, lo, &vis)? { - return Ok(Some(self.mk_item(lo.to(self.prev_span), ident, kind, vis, attrs))); + return Ok(Some(P(self.mk_item(lo, ident, kind, vis, attrs)))); } // FAILURE TO PARSE ITEM @@ -942,9 +942,7 @@ impl<'a> Parser<'a> { } self.unexpected()? }; - - let span = lo.to(self.prev_span); - Ok(P(ast::ForeignItem { ident, attrs, kind, id: DUMMY_NODE_ID, span, vis, tokens: None })) + Ok(P(self.mk_item(lo, ident, kind, vis, attrs))) } /// Parses a static item from a foreign module. @@ -1364,7 +1362,7 @@ impl<'a> Parser<'a> { } /// Is this unambiguously the start of a `macro_rules! foo` item defnition? - fn is_macro_rules_item(&mut self) -> bool { + pub(super) fn is_macro_rules_item(&mut self) -> bool { self.check_keyword(sym::macro_rules) && self.look_ahead(1, |t| *t == token::Not) && self.look_ahead(2, |t| t.is_ident()) @@ -1385,22 +1383,6 @@ impl<'a> Parser<'a> { Ok((ident, ItemKind::MacroDef(ast::MacroDef { body, legacy: true }))) } - pub(super) fn eat_macro_def( - &mut self, - attrs: &[Attribute], - vis: &Visibility, - lo: Span, - ) -> PResult<'a, Option<P<Item>>> { - let (ident, kind) = if self.eat_keyword(kw::Macro) { - self.parse_item_decl_macro(lo)? - } else if self.is_macro_rules_item() { - self.parse_item_macro_rules(vis)? - } else { - return Ok(None); - }; - Ok(Some(self.mk_item(lo.to(self.prev_span), ident, kind, vis.clone(), attrs.to_vec()))) - } - fn complain_if_pub_macro(&self, vis: &VisibilityKind, sp: Span) { match *vis { VisibilityKind::Inherited => {} @@ -1496,15 +1478,16 @@ impl<'a> Parser<'a> { Ok(true) } - fn mk_item( + fn mk_item<K>( &self, - span: Span, + lo: Span, ident: Ident, - kind: ItemKind, + kind: K, vis: Visibility, attrs: Vec<Attribute>, - ) -> P<Item> { - P(Item { ident, attrs, id: DUMMY_NODE_ID, kind, vis, span, tokens: None }) + ) -> Item<K> { + let span = lo.to(self.prev_span); + Item { ident, attrs, id: DUMMY_NODE_ID, kind, vis, span, tokens: None } } } diff --git a/src/librustc_parse/parser/stmt.rs b/src/librustc_parse/parser/stmt.rs index e97af0dc00c..b111b45e709 100644 --- a/src/librustc_parse/parser/stmt.rs +++ b/src/librustc_parse/parser/stmt.rs @@ -7,10 +7,10 @@ use crate::maybe_whole; use crate::DirectoryOwnership; use rustc_errors::{Applicability, PResult}; -use rustc_span::source_map::{respan, BytePos, Span}; +use rustc_span::source_map::{BytePos, Span}; use rustc_span::symbol::{kw, sym, Symbol}; use syntax::ast; -use syntax::ast::{AttrStyle, AttrVec, Attribute, Mac, MacStmtStyle, VisibilityKind}; +use syntax::ast::{AttrStyle, AttrVec, Attribute, Mac, MacStmtStyle}; use syntax::ast::{Block, BlockCheckMode, Expr, ExprKind, Local, Stmt, StmtKind, DUMMY_NODE_ID}; use syntax::ptr::P; use syntax::token::{self, TokenKind}; @@ -55,11 +55,6 @@ impl<'a> Parser<'a> { return self.recover_stmt_local(lo, attrs.into(), msg, "let"); } - let mac_vis = respan(lo, VisibilityKind::Inherited); - if let Some(macro_def) = self.eat_macro_def(&attrs, &mac_vis, lo)? { - return Ok(Some(self.mk_stmt(lo.to(self.prev_span), StmtKind::Item(macro_def)))); - } - // Starts like a simple path, being careful to avoid contextual keywords // such as a union items, item with `crate` visibility or auto trait items. // Our goal here is to parse an arbitrary path `a::b::c` but not something that starts @@ -70,6 +65,7 @@ impl<'a> Parser<'a> { && !self.is_crate_vis() // `crate::b::c` - path, `crate struct S;` - not a path. && !self.is_auto_trait_item() && !self.is_async_fn() + && !self.is_macro_rules_item() { let path = self.parse_path(PathStyle::Expr)?; |
