diff options
| author | Manish Goregaokar <manishsmail@gmail.com> | 2016-06-29 21:21:21 +0530 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2016-06-29 21:21:21 +0530 |
| commit | fd45e6e9127e737ad7d7bca5efe3c50b0dab03f7 (patch) | |
| tree | efa5b5d02389e82c7b683bab044b9977c0760e6f /src/libsyntax | |
| parent | 470c5191f553eb86a3a849e88d642dbd09a32e25 (diff) | |
| parent | e58963d3e45895c150a8c5894c2b7ad87b448568 (diff) | |
| download | rust-fd45e6e9127e737ad7d7bca5efe3c50b0dab03f7.tar.gz rust-fd45e6e9127e737ad7d7bca5efe3c50b0dab03f7.zip | |
Rollup merge of #34459 - jseyfried:expansion_cleanup, r=nrc
Miscellaneous macro expansion cleanup and groundwork r? @nrc
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/ast.rs | 10 | ||||
| -rw-r--r-- | src/libsyntax/attr.rs | 4 | ||||
| -rw-r--r-- | src/libsyntax/config.rs | 7 | ||||
| -rw-r--r-- | src/libsyntax/ext/base.rs | 4 | ||||
| -rw-r--r-- | src/libsyntax/ext/expand.rs | 32 |
5 files changed, 20 insertions, 37 deletions
diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index a352715b20b..cc033cec8b8 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -19,7 +19,6 @@ pub use util::ThinVec; use syntax_pos::{mk_sp, Span, DUMMY_SP, ExpnId}; use codemap::{respan, Spanned}; use abi::Abi; -use errors; use parse::token::{self, keywords, InternedString}; use print::pprust; use ptr::P; @@ -362,15 +361,6 @@ pub const CRATE_NODE_ID: NodeId = 0; /// small, positive ids. pub const DUMMY_NODE_ID: NodeId = !0; -pub trait NodeIdAssigner { - fn next_node_id(&self) -> NodeId; - fn peek_node_id(&self) -> NodeId; - - fn diagnostic(&self) -> &errors::Handler { - panic!("this ID assigner cannot emit diagnostics") - } -} - /// The AST represents all type param bounds as types. /// typeck::collect::compute_bounds matches these against /// the "special" built-in traits (see middle::lang_items) and diff --git a/src/libsyntax/attr.rs b/src/libsyntax/attr.rs index da2967e306f..3c88fb8f670 100644 --- a/src/libsyntax/attr.rs +++ b/src/libsyntax/attr.rs @@ -839,7 +839,7 @@ impl HasAttrs for StmtKind { fn attrs(&self) -> &[Attribute] { match *self { StmtKind::Local(ref local) => local.attrs(), - StmtKind::Item(ref item) => item.attrs(), + StmtKind::Item(..) => &[], StmtKind::Expr(ref expr) | StmtKind::Semi(ref expr) => expr.attrs(), StmtKind::Mac(ref mac) => { let (_, _, ref attrs) = **mac; @@ -851,7 +851,7 @@ impl HasAttrs for StmtKind { fn map_attrs<F: FnOnce(Vec<Attribute>) -> Vec<Attribute>>(self, f: F) -> Self { match self { StmtKind::Local(local) => StmtKind::Local(local.map_attrs(f)), - StmtKind::Item(item) => StmtKind::Item(item.map_attrs(f)), + StmtKind::Item(..) => self, StmtKind::Expr(expr) => StmtKind::Expr(expr.map_attrs(f)), StmtKind::Semi(expr) => StmtKind::Semi(expr.map_attrs(f)), StmtKind::Mac(mac) => StmtKind::Mac(mac.map(|(mac, style, attrs)| { diff --git a/src/libsyntax/config.rs b/src/libsyntax/config.rs index 961763c6025..eaf82f5f43d 100644 --- a/src/libsyntax/config.rs +++ b/src/libsyntax/config.rs @@ -213,12 +213,7 @@ impl<'a> fold::Folder for StripUnconfigured<'a> { } fn fold_stmt(&mut self, stmt: ast::Stmt) -> SmallVector<ast::Stmt> { - // avoid calling `visit_stmt_or_expr_attrs` on items - match stmt.node { - ast::StmtKind::Item(_) => {} - _ => self.visit_stmt_or_expr_attrs(stmt.attrs()), - } - + self.visit_stmt_or_expr_attrs(stmt.attrs()); self.configure(stmt).map(|stmt| fold::noop_fold_stmt(stmt, self)) .unwrap_or(SmallVector::zero()) } diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index 757b039fcac..ca38ef068d0 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -443,6 +443,10 @@ impl MacResult for DummyResult { span: self.span, })) } + + fn make_ty(self: Box<DummyResult>) -> Option<P<ast::Ty>> { + Some(DummyResult::raw_ty(self.span)) + } } /// An enum representing the different kinds of syntax extensions. diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index a10d8900140..aca1fae6a3c 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -43,18 +43,19 @@ trait MacroGenerable: Sized { fn fold_with<F: Folder>(self, folder: &mut F) -> Self; fn visit_with<V: Visitor>(&self, visitor: &mut V); - // Return a placeholder expansion to allow compilation to continue after an erroring expansion. - fn dummy(span: Span) -> Self; - // The user-friendly name of the node type (e.g. "expression", "item", etc.) for diagnostics. fn kind_name() -> &'static str; + + // Return a placeholder expansion to allow compilation to continue after an erroring expansion. + fn dummy(span: Span) -> Self { + Self::make_with(DummyResult::any(span)).unwrap() + } } macro_rules! impl_macro_generable { ($($ty:ty: $kind_name:expr, .$make:ident, $(.$fold:ident)* $(lift .$fold_elt:ident)*, - $(.$visit:ident)* $(lift .$visit_elt:ident)*, - |$span:ident| $dummy:expr;)*) => { $( + $(.$visit:ident)* $(lift .$visit_elt:ident)*;)*) => { $( impl MacroGenerable for $ty { fn kind_name() -> &'static str { $kind_name } fn make_with<'a>(result: Box<MacResult + 'a>) -> Option<Self> { result.$make() } @@ -66,31 +67,24 @@ macro_rules! impl_macro_generable { $( visitor.$visit(self) )* $( for item in self.as_slice() { visitor. $visit_elt (item) } )* } - fn dummy($span: Span) -> Self { $dummy } } )* } } impl_macro_generable! { - P<ast::Pat>: "pattern", .make_pat, .fold_pat, .visit_pat, |span| P(DummyResult::raw_pat(span)); - P<ast::Ty>: "type", .make_ty, .fold_ty, .visit_ty, |span| DummyResult::raw_ty(span); - P<ast::Expr>: - "expression", .make_expr, .fold_expr, .visit_expr, |span| DummyResult::raw_expr(span); - SmallVector<ast::Stmt>: - "statement", .make_stmts, lift .fold_stmt, lift .visit_stmt, |_span| SmallVector::zero(); - SmallVector<P<ast::Item>>: - "item", .make_items, lift .fold_item, lift .visit_item, |_span| SmallVector::zero(); + P<ast::Expr>: "expression", .make_expr, .fold_expr, .visit_expr; + P<ast::Pat>: "pattern", .make_pat, .fold_pat, .visit_pat; + P<ast::Ty>: "type", .make_ty, .fold_ty, .visit_ty; + SmallVector<ast::Stmt>: "statement", .make_stmts, lift .fold_stmt, lift .visit_stmt; + SmallVector<P<ast::Item>>: "item", .make_items, lift .fold_item, lift .visit_item; SmallVector<ast::TraitItem>: - "trait item", .make_trait_items, lift .fold_trait_item, lift .visit_trait_item, - |_span| SmallVector::zero(); + "trait item", .make_trait_items, lift .fold_trait_item, lift .visit_trait_item; SmallVector<ast::ImplItem>: - "impl item", .make_impl_items, lift .fold_impl_item, lift .visit_impl_item, - |_span| SmallVector::zero(); + "impl item", .make_impl_items, lift .fold_impl_item, lift .visit_impl_item; } impl MacroGenerable for Option<P<ast::Expr>> { fn kind_name() -> &'static str { "expression" } - fn dummy(_span: Span) -> Self { None } fn make_with<'a>(result: Box<MacResult + 'a>) -> Option<Self> { result.make_expr().map(Some) } |
