]> git.lizzy.rs Git - rust.git/blobdiff - src/libsyntax/ext/expand.rs
Rename `Ty.node` to `Ty.kind`
[rust.git] / src / libsyntax / ext / expand.rs
index 87e2d721f89a0954b237b4310310e3a6db80e053..98a4de4cfe94f7a1d41d2c91b86a9bf732af9ae4 100644 (file)
@@ -6,7 +6,7 @@
 use crate::ext::base::*;
 use crate::ext::proc_macro::{collect_derives, MarkAttrs};
 use crate::ext::hygiene::{ExpnId, SyntaxContext, ExpnData, ExpnKind};
-use crate::ext::tt::macro_rules::annotate_err_with_kind;
+use crate::ext::mbe::macro_rules::annotate_err_with_kind;
 use crate::ext::placeholders::{placeholder, PlaceholderExpander};
 use crate::feature_gate::{self, Features, GateIssue, is_builtin_attr, emit_feature_err};
 use crate::mut_visit::*;
@@ -26,7 +26,7 @@
 use rustc_data_structures::fx::FxHashMap;
 use rustc_data_structures::sync::Lrc;
 use std::io::ErrorKind;
-use std::{iter, mem};
+use std::{iter, mem, slice};
 use std::ops::DerefMut;
 use std::rc::Rc;
 use std::path::PathBuf;
@@ -115,8 +115,8 @@ pub fn visit_with<'a, V: Visitor<'a>>(&'a self, visitor: &mut V) {
             }
         }
 
-        impl<'a> MacResult for crate::ext::tt::macro_rules::ParserAnyMacro<'a> {
-            $(fn $make_ast(self: Box<crate::ext::tt::macro_rules::ParserAnyMacro<'a>>)
+        impl<'a> MacResult for crate::ext::mbe::macro_rules::ParserAnyMacro<'a> {
+            $(fn $make_ast(self: Box<crate::ext::mbe::macro_rules::ParserAnyMacro<'a>>)
                            -> Option<$AstTy> {
                 Some(self.make(AstFragmentKind::$Kind).$make_ast())
             })*
@@ -384,7 +384,7 @@ pub fn fully_expand_fragment(&mut self, input_fragment: AstFragment) -> AstFragm
                         let attr = attr::find_by_name(item.attrs(), sym::derive)
                             .expect("`derive` attribute should exist");
                         let span = attr.span;
-                        let mut err = self.cx.mut_span_err(span,
+                        let mut err = self.cx.struct_span_err(span,
                             "`derive` may only be applied to structs, enums and unions");
                         if let ast::AttrStyle::Inner = attr.style {
                             let trait_list = derives.iter()
@@ -1019,7 +1019,7 @@ fn configure<T: HasAttrs>(&mut self, node: T) -> Option<T> {
     fn check_attributes(&mut self, attrs: &[ast::Attribute]) {
         let features = self.cx.ecfg.features.unwrap();
         for attr in attrs.iter() {
-            self.check_attribute_inner(attr, features);
+            feature_gate::check_attribute(attr, self.cx.parse_sess, features);
 
             // macros are expanded before any lint passes so this warning has to be hardcoded
             if attr.path == sym::derive {
@@ -1029,22 +1029,13 @@ fn check_attributes(&mut self, attrs: &[ast::Attribute]) {
             }
         }
     }
-
-    fn check_attribute(&mut self, at: &ast::Attribute) {
-        let features = self.cx.ecfg.features.unwrap();
-        self.check_attribute_inner(at, features);
-    }
-
-    fn check_attribute_inner(&mut self, at: &ast::Attribute, features: &Features) {
-        feature_gate::check_attribute(at, self.cx.parse_sess, features);
-    }
 }
 
 impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> {
     fn visit_expr(&mut self, expr: &mut P<ast::Expr>) {
         self.cfg.configure_expr(expr);
         visit_clobber(expr.deref_mut(), |mut expr| {
-            self.cfg.configure_expr_kind(&mut expr.node);
+            self.cfg.configure_expr_kind(&mut expr.kind);
 
             // ignore derives so they remain unused
             let (attr, after_derive) = self.classify_nonitem(&mut expr);
@@ -1061,7 +1052,7 @@ fn visit_expr(&mut self, expr: &mut P<ast::Expr>) {
                     .into_inner()
             }
 
-            if let ast::ExprKind::Mac(mac) = expr.node {
+            if let ast::ExprKind::Mac(mac) = expr.kind {
                 self.check_attributes(&expr.attrs);
                 self.collect_bang(mac, expr.span, AstFragmentKind::Expr)
                     .make_expr()
@@ -1154,7 +1145,7 @@ fn visit_expr(&mut self, expr: &mut P<ast::Expr>) {
     fn filter_map_expr(&mut self, expr: P<ast::Expr>) -> Option<P<ast::Expr>> {
         let expr = configure!(self, expr);
         expr.filter_map(|mut expr| {
-            self.cfg.configure_expr_kind(&mut expr.node);
+            self.cfg.configure_expr_kind(&mut expr.kind);
 
             // Ignore derives so they remain unused.
             let (attr, after_derive) = self.classify_nonitem(&mut expr);
@@ -1168,7 +1159,7 @@ fn filter_map_expr(&mut self, expr: P<ast::Expr>) -> Option<P<ast::Expr>> {
                     .map(|expr| expr.into_inner())
             }
 
-            if let ast::ExprKind::Mac(mac) = expr.node {
+            if let ast::ExprKind::Mac(mac) = expr.kind {
                 self.check_attributes(&expr.attrs);
                 self.collect_bang(mac, expr.span, AstFragmentKind::OptExpr)
                     .make_opt_expr()
@@ -1181,13 +1172,13 @@ fn filter_map_expr(&mut self, expr: P<ast::Expr>) -> Option<P<ast::Expr>> {
 
     fn visit_pat(&mut self, pat: &mut P<ast::Pat>) {
         self.cfg.configure_pat(pat);
-        match pat.node {
+        match pat.kind {
             PatKind::Mac(_) => {}
             _ => return noop_visit_pat(pat, self),
         }
 
         visit_clobber(pat, |mut pat| {
-            match mem::replace(&mut pat.node, PatKind::Wild) {
+            match mem::replace(&mut pat.kind, PatKind::Wild) {
                 PatKind::Mac(mac) =>
                     self.collect_bang(mac, pat.span, AstFragmentKind::Pat).make_pat(),
                 _ => unreachable!(),
@@ -1327,7 +1318,7 @@ fn visit_block(&mut self, block: &mut P<Block>) {
                                      AstFragmentKind::TraitItems, after_derive).make_trait_items()
         }
 
-        match item.node {
+        match item.kind {
             ast::TraitItemKind::Macro(mac) => {
                 let ast::TraitItem { attrs, span, .. } = item;
                 self.check_attributes(&attrs);
@@ -1346,7 +1337,7 @@ fn visit_block(&mut self, block: &mut P<Block>) {
                                      AstFragmentKind::ImplItems, after_derive).make_impl_items();
         }
 
-        match item.node {
+        match item.kind {
             ast::ImplItemKind::Macro(mac) => {
                 let ast::ImplItem { attrs, span, .. } = item;
                 self.check_attributes(&attrs);
@@ -1357,13 +1348,13 @@ fn visit_block(&mut self, block: &mut P<Block>) {
     }
 
     fn visit_ty(&mut self, ty: &mut P<ast::Ty>) {
-        match ty.node {
+        match ty.kind {
             ast::TyKind::Mac(_) => {}
             _ => return noop_visit_ty(ty, self),
         };
 
         visit_clobber(ty, |mut ty| {
-            match mem::replace(&mut ty.node, ast::TyKind::Err) {
+            match mem::replace(&mut ty.kind, ast::TyKind::Err) {
                 ast::TyKind::Mac(mac) =>
                     self.collect_bang(mac, ty.span, AstFragmentKind::Ty).make_ty(),
                 _ => unreachable!(),
@@ -1445,7 +1436,7 @@ fn visit_attribute(&mut self, at: &mut ast::Attribute) {
 
                 if let Some(file) = it.value_str() {
                     let err_count = self.cx.parse_sess.span_diagnostic.err_count();
-                    self.check_attribute(&at);
+                    self.check_attributes(slice::from_ref(at));
                     if self.cx.parse_sess.span_diagnostic.err_count() > err_count {
                         // avoid loading the file if they haven't enabled the feature
                         return noop_visit_attribute(at, self);
@@ -1513,7 +1504,7 @@ fn visit_attribute(&mut self, at: &mut ast::Attribute) {
                     // Check if the user erroneously used `doc(include(...))` syntax.
                     let literal = it.meta_item_list().and_then(|list| {
                         if list.len() == 1 {
-                            list[0].literal().map(|literal| &literal.node)
+                            list[0].literal().map(|literal| &literal.kind)
                         } else {
                             None
                         }