Skip to content

Commit 200a08f

Browse files
committed
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]
1 parent 313cb8a commit 200a08f

File tree

2 files changed

+13
-37
lines changed

2 files changed

+13
-37
lines changed

src/librustc/plugin/registry.rs

+3-8
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
use lint::{LintPassObject, LintId, Lint};
1414

1515
use syntax::ext::base::{SyntaxExtension, NamedSyntaxExtension, NormalTT};
16-
use syntax::ext::base::{IdentTT, LetSyntaxTT, ItemDecorator, ItemModifier, BasicMacroExpander};
16+
use syntax::ext::base::{IdentTT, LetSyntaxTT, ItemDecorator, ItemModifier};
1717
use syntax::ext::base::{MacroExpanderFn};
1818
use syntax::codemap::Span;
1919
use syntax::parse::token;
@@ -71,15 +71,10 @@ impl Registry {
7171
/// Register a macro of the usual kind.
7272
///
7373
/// This is a convenience wrapper for `register_syntax_extension`.
74-
/// It builds for you a `NormalTT` with a `BasicMacroExpander`,
74+
/// It builds for you a `NormalTT` that calls `expander`,
7575
/// and also takes care of interning the macro's name.
7676
pub fn register_macro(&mut self, name: &str, expander: MacroExpanderFn) {
77-
self.register_syntax_extension(
78-
token::intern(name),
79-
NormalTT(box BasicMacroExpander {
80-
expander: expander,
81-
span: None,
82-
}, None));
77+
self.register_syntax_extension(token::intern(name), NormalTT(box expander, None));
8378
}
8479

8580
/// Register a compiler lint pass.

src/libsyntax/ext/base.rs

+10-29
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,6 @@ impl ItemModifier for fn(&mut ExtCtxt, Span, Gc<ast::MetaItem>, Gc<ast::Item>) -
7979
}
8080
}
8181

82-
pub struct BasicMacroExpander {
83-
pub expander: MacroExpanderFn,
84-
pub span: Option<Span>
85-
}
86-
8782
/// Represents a thing that maps token trees to Macro Results
8883
pub trait TTMacroExpander {
8984
fn expand<'cx>(&self,
@@ -94,24 +89,18 @@ pub trait TTMacroExpander {
9489
}
9590

9691
pub type MacroExpanderFn =
97-
fn<'cx>(ecx: &'cx mut ExtCtxt, span: codemap::Span, token_tree: &[ast::TokenTree])
98-
-> Box<MacResult+'cx>;
92+
fn<'cx>(&'cx mut ExtCtxt, Span, &[ast::TokenTree]) -> Box<MacResult+'cx>;
9993

100-
impl TTMacroExpander for BasicMacroExpander {
94+
impl TTMacroExpander for MacroExpanderFn {
10195
fn expand<'cx>(&self,
10296
ecx: &'cx mut ExtCtxt,
10397
span: Span,
10498
token_tree: &[ast::TokenTree])
10599
-> Box<MacResult+'cx> {
106-
(self.expander)(ecx, span, token_tree)
100+
(*self)(ecx, span, token_tree)
107101
}
108102
}
109103

110-
pub struct BasicIdentMacroExpander {
111-
pub expander: IdentMacroExpanderFn,
112-
pub span: Option<Span>
113-
}
114-
115104
pub trait IdentMacroExpander {
116105
fn expand<'cx>(&self,
117106
cx: &'cx mut ExtCtxt,
@@ -121,20 +110,20 @@ pub trait IdentMacroExpander {
121110
-> Box<MacResult+'cx>;
122111
}
123112

124-
impl IdentMacroExpander for BasicIdentMacroExpander {
113+
pub type IdentMacroExpanderFn =
114+
fn<'cx>(&'cx mut ExtCtxt, Span, ast::Ident, Vec<ast::TokenTree>) -> Box<MacResult+'cx>;
115+
116+
impl IdentMacroExpander for IdentMacroExpanderFn {
125117
fn expand<'cx>(&self,
126118
cx: &'cx mut ExtCtxt,
127119
sp: Span,
128120
ident: ast::Ident,
129121
token_tree: Vec<ast::TokenTree> )
130122
-> Box<MacResult+'cx> {
131-
(self.expander)(cx, sp, ident, token_tree)
123+
(*self)(cx, sp, ident, token_tree)
132124
}
133125
}
134126

135-
pub type IdentMacroExpanderFn =
136-
fn<'cx>(&'cx mut ExtCtxt, Span, ast::Ident, Vec<ast::TokenTree>) -> Box<MacResult+'cx>;
137-
138127
/// The result of a macro expansion. The return values of the various
139128
/// methods are spliced into the AST at the callsite of the macro (or
140129
/// just into the compiler's internal macro table, for `make_def`).
@@ -363,20 +352,12 @@ impl BlockInfo {
363352
fn initial_syntax_expander_table() -> SyntaxEnv {
364353
// utility function to simplify creating NormalTT syntax extensions
365354
fn builtin_normal_expander(f: MacroExpanderFn) -> SyntaxExtension {
366-
NormalTT(box BasicMacroExpander {
367-
expander: f,
368-
span: None,
369-
},
370-
None)
355+
NormalTT(box f, None)
371356
}
372357

373358
let mut syntax_expanders = SyntaxEnv::new();
374359
syntax_expanders.insert(intern("macro_rules"),
375-
LetSyntaxTT(box BasicIdentMacroExpander {
376-
expander: ext::tt::macro_rules::add_new_extension,
377-
span: None,
378-
},
379-
None));
360+
LetSyntaxTT(box ext::tt::macro_rules::add_new_extension, None));
380361
syntax_expanders.insert(intern("fmt"),
381362
builtin_normal_expander(
382363
ext::fmt::expand_syntax_ext));

0 commit comments

Comments
 (0)