]> git.lizzy.rs Git - rust.git/blobdiff - compiler/rustc_expand/src/expand.rs
Remove `crate` visibility usage in compiler
[rust.git] / compiler / rustc_expand / src / expand.rs
index 5bd89f3f42fa563c01888fee0d3904a16ef233c8..676abc92b633fd77b948cd06f4ab1c73ae2f7cdc 100644 (file)
@@ -11,7 +11,8 @@
 use rustc_ast::token::{self, Delimiter};
 use rustc_ast::tokenstream::TokenStream;
 use rustc_ast::visit::{self, AssocCtxt, Visitor};
-use rustc_ast::{AssocItemKind, AstLike, AstLikeWrapper, AttrStyle, ExprKind, ForeignItemKind};
+use rustc_ast::{AssocItemKind, AstNodeWrapper, AttrStyle, ExprKind, ForeignItemKind};
+use rustc_ast::{HasAttrs, HasNodeId};
 use rustc_ast::{Inline, ItemKind, MacArgs, MacStmtStyle, MetaItemKind, ModKind};
 use rustc_ast::{NestedMetaItem, NodeId, PatKind, StmtKind, TyKind};
 use rustc_ast_pretty::pprust;
@@ -213,7 +214,7 @@ pub enum SupportsMacroExpansion {
 }
 
 impl AstFragmentKind {
-    crate fn dummy(self, span: Span) -> AstFragment {
+    pub(crate) fn dummy(self, span: Span) -> AstFragment {
         self.make_from(DummyResult::any(span)).expect("couldn't create a dummy AST fragment")
     }
 
@@ -678,12 +679,9 @@ fn expand_invoc(
                                     )
                                 ) =>
                         {
-                            rustc_parse::fake_token_stream(
-                                &self.cx.sess.parse_sess,
-                                &item.into_nonterminal(),
-                            )
+                            rustc_parse::fake_token_stream(&self.cx.sess.parse_sess, item_inner)
                         }
-                        _ => item.into_tokens(&self.cx.sess.parse_sess),
+                        _ => item.to_tokens(&self.cx.sess.parse_sess),
                     };
                     let attr_item = attr.unwrap_normal_item();
                     if let MacArgs::Eq(..) = attr_item.args {
@@ -998,13 +996,12 @@ enum AddSemicolon {
 
 /// A trait implemented for all `AstFragment` nodes and providing all pieces
 /// of functionality used by `InvocationCollector`.
-trait InvocationCollectorNode: AstLike {
+trait InvocationCollectorNode: HasAttrs + HasNodeId + Sized {
     type OutputTy = SmallVec<[Self; 1]>;
     type AttrsTy: Deref<Target = [ast::Attribute]> = Vec<ast::Attribute>;
     const KIND: AstFragmentKind;
     fn to_annotatable(self) -> Annotatable;
     fn fragment_to_output(fragment: AstFragment) -> Self::OutputTy;
-    fn id(&mut self) -> &mut NodeId;
     fn descr() -> &'static str {
         unreachable!()
     }
@@ -1040,9 +1037,6 @@ fn to_annotatable(self) -> Annotatable {
     fn fragment_to_output(fragment: AstFragment) -> Self::OutputTy {
         fragment.make_items()
     }
-    fn id(&mut self) -> &mut NodeId {
-        &mut self.id
-    }
     fn noop_flat_map<V: MutVisitor>(self, visitor: &mut V) -> Self::OutputTy {
         noop_flat_map_item(self, visitor)
     }
@@ -1142,7 +1136,7 @@ fn wrap_flat_map_node_noop_flat_map(
 }
 
 struct TraitItemTag;
-impl InvocationCollectorNode for AstLikeWrapper<P<ast::AssocItem>, TraitItemTag> {
+impl InvocationCollectorNode for AstNodeWrapper<P<ast::AssocItem>, TraitItemTag> {
     type OutputTy = SmallVec<[P<ast::AssocItem>; 1]>;
     const KIND: AstFragmentKind = AstFragmentKind::TraitItems;
     fn to_annotatable(self) -> Annotatable {
@@ -1151,9 +1145,6 @@ fn to_annotatable(self) -> Annotatable {
     fn fragment_to_output(fragment: AstFragment) -> Self::OutputTy {
         fragment.make_trait_items()
     }
-    fn id(&mut self) -> &mut NodeId {
-        &mut self.wrapped.id
-    }
     fn noop_flat_map<V: MutVisitor>(self, visitor: &mut V) -> Self::OutputTy {
         noop_flat_map_assoc_item(self.wrapped, visitor)
     }
@@ -1170,7 +1161,7 @@ fn take_mac_call(self) -> (ast::MacCall, Self::AttrsTy, AddSemicolon) {
 }
 
 struct ImplItemTag;
-impl InvocationCollectorNode for AstLikeWrapper<P<ast::AssocItem>, ImplItemTag> {
+impl InvocationCollectorNode for AstNodeWrapper<P<ast::AssocItem>, ImplItemTag> {
     type OutputTy = SmallVec<[P<ast::AssocItem>; 1]>;
     const KIND: AstFragmentKind = AstFragmentKind::ImplItems;
     fn to_annotatable(self) -> Annotatable {
@@ -1179,9 +1170,6 @@ fn to_annotatable(self) -> Annotatable {
     fn fragment_to_output(fragment: AstFragment) -> Self::OutputTy {
         fragment.make_impl_items()
     }
-    fn id(&mut self) -> &mut NodeId {
-        &mut self.wrapped.id
-    }
     fn noop_flat_map<V: MutVisitor>(self, visitor: &mut V) -> Self::OutputTy {
         noop_flat_map_assoc_item(self.wrapped, visitor)
     }
@@ -1205,9 +1193,6 @@ fn to_annotatable(self) -> Annotatable {
     fn fragment_to_output(fragment: AstFragment) -> Self::OutputTy {
         fragment.make_foreign_items()
     }
-    fn id(&mut self) -> &mut NodeId {
-        &mut self.id
-    }
     fn noop_flat_map<V: MutVisitor>(self, visitor: &mut V) -> Self::OutputTy {
         noop_flat_map_foreign_item(self, visitor)
     }
@@ -1231,9 +1216,6 @@ fn to_annotatable(self) -> Annotatable {
     fn fragment_to_output(fragment: AstFragment) -> Self::OutputTy {
         fragment.make_variants()
     }
-    fn id(&mut self) -> &mut NodeId {
-        &mut self.id
-    }
     fn noop_flat_map<V: MutVisitor>(self, visitor: &mut V) -> Self::OutputTy {
         noop_flat_map_variant(self, visitor)
     }
@@ -1247,9 +1229,6 @@ fn to_annotatable(self) -> Annotatable {
     fn fragment_to_output(fragment: AstFragment) -> Self::OutputTy {
         fragment.make_field_defs()
     }
-    fn id(&mut self) -> &mut NodeId {
-        &mut self.id
-    }
     fn noop_flat_map<V: MutVisitor>(self, visitor: &mut V) -> Self::OutputTy {
         noop_flat_map_field_def(self, visitor)
     }
@@ -1263,9 +1242,6 @@ fn to_annotatable(self) -> Annotatable {
     fn fragment_to_output(fragment: AstFragment) -> Self::OutputTy {
         fragment.make_pat_fields()
     }
-    fn id(&mut self) -> &mut NodeId {
-        &mut self.id
-    }
     fn noop_flat_map<V: MutVisitor>(self, visitor: &mut V) -> Self::OutputTy {
         noop_flat_map_pat_field(self, visitor)
     }
@@ -1279,9 +1255,6 @@ fn to_annotatable(self) -> Annotatable {
     fn fragment_to_output(fragment: AstFragment) -> Self::OutputTy {
         fragment.make_expr_fields()
     }
-    fn id(&mut self) -> &mut NodeId {
-        &mut self.id
-    }
     fn noop_flat_map<V: MutVisitor>(self, visitor: &mut V) -> Self::OutputTy {
         noop_flat_map_expr_field(self, visitor)
     }
@@ -1295,9 +1268,6 @@ fn to_annotatable(self) -> Annotatable {
     fn fragment_to_output(fragment: AstFragment) -> Self::OutputTy {
         fragment.make_params()
     }
-    fn id(&mut self) -> &mut NodeId {
-        &mut self.id
-    }
     fn noop_flat_map<V: MutVisitor>(self, visitor: &mut V) -> Self::OutputTy {
         noop_flat_map_param(self, visitor)
     }
@@ -1311,9 +1281,6 @@ fn to_annotatable(self) -> Annotatable {
     fn fragment_to_output(fragment: AstFragment) -> Self::OutputTy {
         fragment.make_generic_params()
     }
-    fn id(&mut self) -> &mut NodeId {
-        &mut self.id
-    }
     fn noop_flat_map<V: MutVisitor>(self, visitor: &mut V) -> Self::OutputTy {
         noop_flat_map_generic_param(self, visitor)
     }
@@ -1327,9 +1294,6 @@ fn to_annotatable(self) -> Annotatable {
     fn fragment_to_output(fragment: AstFragment) -> Self::OutputTy {
         fragment.make_arms()
     }
-    fn id(&mut self) -> &mut NodeId {
-        &mut self.id
-    }
     fn noop_flat_map<V: MutVisitor>(self, visitor: &mut V) -> Self::OutputTy {
         noop_flat_map_arm(self, visitor)
     }
@@ -1344,9 +1308,6 @@ fn to_annotatable(self) -> Annotatable {
     fn fragment_to_output(fragment: AstFragment) -> Self::OutputTy {
         fragment.make_stmts()
     }
-    fn id(&mut self) -> &mut NodeId {
-        &mut self.id
-    }
     fn noop_flat_map<V: MutVisitor>(self, visitor: &mut V) -> Self::OutputTy {
         noop_flat_map_stmt(self, visitor)
     }
@@ -1403,9 +1364,6 @@ fn to_annotatable(self) -> Annotatable {
     fn fragment_to_output(fragment: AstFragment) -> Self::OutputTy {
         fragment.make_crate()
     }
-    fn id(&mut self) -> &mut NodeId {
-        &mut self.id
-    }
     fn noop_visit<V: MutVisitor>(&mut self, visitor: &mut V) {
         noop_visit_crate(self, visitor)
     }
@@ -1420,9 +1378,6 @@ fn to_annotatable(self) -> Annotatable {
     fn fragment_to_output(fragment: AstFragment) -> Self::OutputTy {
         fragment.make_ty()
     }
-    fn id(&mut self) -> &mut NodeId {
-        &mut self.id
-    }
     fn noop_visit<V: MutVisitor>(&mut self, visitor: &mut V) {
         noop_visit_ty(self, visitor)
     }
@@ -1447,9 +1402,6 @@ fn to_annotatable(self) -> Annotatable {
     fn fragment_to_output(fragment: AstFragment) -> Self::OutputTy {
         fragment.make_pat()
     }
-    fn id(&mut self) -> &mut NodeId {
-        &mut self.id
-    }
     fn noop_visit<V: MutVisitor>(&mut self, visitor: &mut V) {
         noop_visit_pat(self, visitor)
     }
@@ -1475,9 +1427,6 @@ fn to_annotatable(self) -> Annotatable {
     fn fragment_to_output(fragment: AstFragment) -> Self::OutputTy {
         fragment.make_expr()
     }
-    fn id(&mut self) -> &mut NodeId {
-        &mut self.id
-    }
     fn descr() -> &'static str {
         "an expression"
     }
@@ -1497,7 +1446,7 @@ fn take_mac_call(self) -> (ast::MacCall, Self::AttrsTy, AddSemicolon) {
 }
 
 struct OptExprTag;
-impl InvocationCollectorNode for AstLikeWrapper<P<ast::Expr>, OptExprTag> {
+impl InvocationCollectorNode for AstNodeWrapper<P<ast::Expr>, OptExprTag> {
     type OutputTy = Option<P<ast::Expr>>;
     type AttrsTy = ast::AttrVec;
     const KIND: AstFragmentKind = AstFragmentKind::OptExpr;
@@ -1507,9 +1456,6 @@ fn to_annotatable(self) -> Annotatable {
     fn fragment_to_output(fragment: AstFragment) -> Self::OutputTy {
         fragment.make_opt_expr()
     }
-    fn id(&mut self) -> &mut NodeId {
-        &mut self.wrapped.id
-    }
     fn noop_flat_map<V: MutVisitor>(mut self, visitor: &mut V) -> Self::OutputTy {
         noop_visit_expr(&mut self.wrapped, visitor);
         Some(self.wrapped)
@@ -1584,7 +1530,7 @@ fn collect_attr(
     /// legacy derive helpers (helpers written before derives that introduce them).
     fn take_first_attr(
         &self,
-        item: &mut impl AstLike,
+        item: &mut impl HasAttrs,
     ) -> Option<(ast::Attribute, usize, Vec<ast::Path>)> {
         let mut attr = None;
 
@@ -1680,7 +1626,7 @@ fn check_attributes(&self, attrs: &[ast::Attribute], call: &ast::MacCall) {
 
     fn expand_cfg_true(
         &mut self,
-        node: &mut impl AstLike,
+        node: &mut impl HasAttrs,
         attr: ast::Attribute,
         pos: usize,
     ) -> bool {
@@ -1695,7 +1641,7 @@ fn expand_cfg_true(
         res
     }
 
-    fn expand_cfg_attr(&self, node: &mut impl AstLike, attr: ast::Attribute, pos: usize) {
+    fn expand_cfg_attr(&self, node: &mut impl HasAttrs, attr: ast::Attribute, pos: usize) {
         node.visit_attrs(|attrs| {
             attrs.splice(pos..pos, self.cfg().expand_cfg_attr(attr, false));
         });
@@ -1733,7 +1679,7 @@ fn flat_map_node<Node: InvocationCollectorNode<OutputTy: Default>>(
                 }
                 None => {
                     match Node::wrap_flat_map_node_noop_flat_map(node, self, |mut node, this| {
-                        assign_id!(this, node.id(), || node.noop_flat_map(this))
+                        assign_id!(this, node.node_id_mut(), || node.noop_flat_map(this))
                     }) {
                         Ok(output) => output,
                         Err(returned_node) => {
@@ -1781,7 +1727,7 @@ fn visit_node<Node: InvocationCollectorNode<OutputTy = Node> + DummyAstNode>(
                     })
                 }
                 None => {
-                    assign_id!(self, node.id(), || node.noop_visit(self))
+                    assign_id!(self, node.node_id_mut(), || node.noop_visit(self))
                 }
             };
         }
@@ -1794,11 +1740,11 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> {
     }
 
     fn flat_map_trait_item(&mut self, node: P<ast::AssocItem>) -> SmallVec<[P<ast::AssocItem>; 1]> {
-        self.flat_map_node(AstLikeWrapper::new(node, TraitItemTag))
+        self.flat_map_node(AstNodeWrapper::new(node, TraitItemTag))
     }
 
     fn flat_map_impl_item(&mut self, node: P<ast::AssocItem>) -> SmallVec<[P<ast::AssocItem>; 1]> {
-        self.flat_map_node(AstLikeWrapper::new(node, ImplItemTag))
+        self.flat_map_node(AstNodeWrapper::new(node, ImplItemTag))
     }
 
     fn flat_map_foreign_item(
@@ -1889,7 +1835,7 @@ fn visit_expr(&mut self, node: &mut P<ast::Expr>) {
     }
 
     fn filter_map_expr(&mut self, node: P<ast::Expr>) -> Option<P<ast::Expr>> {
-        self.flat_map_node(AstLikeWrapper::new(node, OptExprTag))
+        self.flat_map_node(AstNodeWrapper::new(node, OptExprTag))
     }
 
     fn visit_block(&mut self, node: &mut P<ast::Block>) {