about summary refs log tree commit diff
diff options
context:
space:
mode:
authorSteven Fackler <sfackler@gmail.com>2014-09-10 20:59:26 -0700
committerSteven Fackler <sfackler@gmail.com>2014-09-10 21:02:39 -0700
commit200a08fc212374f5650c54489ae26f995c60bad9 (patch)
tree0ea53a5c76cd2ec43b5bb2a125ec156de1967313
parent313cb8acaea05e703441bd5adb92aacce5bf6411 (diff)
downloadrust-200a08fc212374f5650c54489ae26f995c60bad9.tar.gz
rust-200a08fc212374f5650c54489ae26f995c60bad9.zip
Remove BasicMacroExpander and BasicIdentMacroExpander
The spans inside of these types were always None and never used. Pass
the expander function directly instead of wrapping it in one of these
types.

[breaking-change]
-rw-r--r--src/librustc/plugin/registry.rs11
-rw-r--r--src/libsyntax/ext/base.rs39
2 files changed, 13 insertions, 37 deletions
diff --git a/src/librustc/plugin/registry.rs b/src/librustc/plugin/registry.rs
index 7fa3ee0ac63..2b2fc8c94d4 100644
--- a/src/librustc/plugin/registry.rs
+++ b/src/librustc/plugin/registry.rs
@@ -13,7 +13,7 @@
 use lint::{LintPassObject, LintId, Lint};
 
 use syntax::ext::base::{SyntaxExtension, NamedSyntaxExtension, NormalTT};
-use syntax::ext::base::{IdentTT, LetSyntaxTT, ItemDecorator, ItemModifier, BasicMacroExpander};
+use syntax::ext::base::{IdentTT, LetSyntaxTT, ItemDecorator, ItemModifier};
 use syntax::ext::base::{MacroExpanderFn};
 use syntax::codemap::Span;
 use syntax::parse::token;
@@ -71,15 +71,10 @@ impl Registry {
     /// Register a macro of the usual kind.
     ///
     /// This is a convenience wrapper for `register_syntax_extension`.
-    /// It builds for you a `NormalTT` with a `BasicMacroExpander`,
+    /// It builds for you a `NormalTT` that calls `expander`,
     /// and also takes care of interning the macro's name.
     pub fn register_macro(&mut self, name: &str, expander: MacroExpanderFn) {
-        self.register_syntax_extension(
-            token::intern(name),
-            NormalTT(box BasicMacroExpander {
-                expander: expander,
-                span: None,
-            }, None));
+        self.register_syntax_extension(token::intern(name), NormalTT(box expander, None));
     }
 
     /// Register a compiler lint pass.
diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs
index 43be3c227ac..4976e68cc64 100644
--- a/src/libsyntax/ext/base.rs
+++ b/src/libsyntax/ext/base.rs
@@ -79,11 +79,6 @@ impl ItemModifier for fn(&mut ExtCtxt, Span, Gc<ast::MetaItem>, Gc<ast::Item>) -
     }
 }
 
-pub struct BasicMacroExpander {
-    pub expander: MacroExpanderFn,
-    pub span: Option<Span>
-}
-
 /// Represents a thing that maps token trees to Macro Results
 pub trait TTMacroExpander {
     fn expand<'cx>(&self,
@@ -94,24 +89,18 @@ pub trait TTMacroExpander {
 }
 
 pub type MacroExpanderFn =
-    fn<'cx>(ecx: &'cx mut ExtCtxt, span: codemap::Span, token_tree: &[ast::TokenTree])
-            -> Box<MacResult+'cx>;
+    fn<'cx>(&'cx mut ExtCtxt, Span, &[ast::TokenTree]) -> Box<MacResult+'cx>;
 
-impl TTMacroExpander for BasicMacroExpander {
+impl TTMacroExpander for MacroExpanderFn {
     fn expand<'cx>(&self,
                    ecx: &'cx mut ExtCtxt,
                    span: Span,
                    token_tree: &[ast::TokenTree])
                    -> Box<MacResult+'cx> {
-        (self.expander)(ecx, span, token_tree)
+        (*self)(ecx, span, token_tree)
     }
 }
 
-pub struct BasicIdentMacroExpander {
-    pub expander: IdentMacroExpanderFn,
-    pub span: Option<Span>
-}
-
 pub trait IdentMacroExpander {
     fn expand<'cx>(&self,
                    cx: &'cx mut ExtCtxt,
@@ -121,20 +110,20 @@ pub trait IdentMacroExpander {
                    -> Box<MacResult+'cx>;
 }
 
-impl IdentMacroExpander for BasicIdentMacroExpander {
+pub type IdentMacroExpanderFn =
+    fn<'cx>(&'cx mut ExtCtxt, Span, ast::Ident, Vec<ast::TokenTree>) -> Box<MacResult+'cx>;
+
+impl IdentMacroExpander for IdentMacroExpanderFn {
     fn expand<'cx>(&self,
                    cx: &'cx mut ExtCtxt,
                    sp: Span,
                    ident: ast::Ident,
                    token_tree: Vec<ast::TokenTree> )
                    -> Box<MacResult+'cx> {
-        (self.expander)(cx, sp, ident, token_tree)
+        (*self)(cx, sp, ident, token_tree)
     }
 }
 
-pub type IdentMacroExpanderFn =
-    fn<'cx>(&'cx mut ExtCtxt, Span, ast::Ident, Vec<ast::TokenTree>) -> Box<MacResult+'cx>;
-
 /// The result of a macro expansion. The return values of the various
 /// methods are spliced into the AST at the callsite of the macro (or
 /// just into the compiler's internal macro table, for `make_def`).
@@ -363,20 +352,12 @@ impl BlockInfo {
 fn initial_syntax_expander_table() -> SyntaxEnv {
     // utility function to simplify creating NormalTT syntax extensions
     fn builtin_normal_expander(f: MacroExpanderFn) -> SyntaxExtension {
-        NormalTT(box BasicMacroExpander {
-                expander: f,
-                span: None,
-            },
-            None)
+        NormalTT(box f, None)
     }
 
     let mut syntax_expanders = SyntaxEnv::new();
     syntax_expanders.insert(intern("macro_rules"),
-                            LetSyntaxTT(box BasicIdentMacroExpander {
-                                expander: ext::tt::macro_rules::add_new_extension,
-                                span: None,
-                            },
-                            None));
+                            LetSyntaxTT(box ext::tt::macro_rules::add_new_extension, None));
     syntax_expanders.insert(intern("fmt"),
                             builtin_normal_expander(
                                 ext::fmt::expand_syntax_ext));