Skip to content

Commit f66a3f7

Browse files
committedFeb 27, 2015
Replace MacExpr / MacPat / MacItems with MacEager
MacEager is a MacResult implementation for the common case where you've already built each form of AST that you might return. Fixes rust-lang#17637. Based on rust-lang#18814. This is a [breaking-change] for syntax extensions: * MacExpr::new becomes MacEager::expr. * MacPat::new becomes MacEager::pat. * MacItems::new becomes MacEager::items. It takes a SmallVector directly, not an iterator.

16 files changed

+113
-89
lines changed
 

‎src/doc/trpl/plugins.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ extern crate rustc;
7171
use syntax::codemap::Span;
7272
use syntax::parse::token;
7373
use syntax::ast::{TokenTree, TtToken};
74-
use syntax::ext::base::{ExtCtxt, MacResult, DummyResult, MacExpr};
75-
use syntax::ext::build::AstBuilder; // trait for expr_uint
74+
use syntax::ext::base::{ExtCtxt, MacResult, DummyResult, MacEager};
75+
use syntax::ext::build::AstBuilder; // trait for expr_usize
7676
use rustc::plugin::Registry;
7777
7878
fn expand_rn(cx: &mut ExtCtxt, sp: Span, args: &[TokenTree])
@@ -107,7 +107,7 @@ fn expand_rn(cx: &mut ExtCtxt, sp: Span, args: &[TokenTree])
107107
}
108108
}
109109
110-
MacExpr::new(cx.expr_uint(sp, total))
110+
MacEager::expr(cx.expr_usize(sp, total))
111111
}
112112
113113
#[plugin_registrar]
@@ -183,7 +183,7 @@ with
183183
[`syntax::print::pprust::*_to_string`](http://doc.rust-lang.org/syntax/print/pprust/index.html#functions).
184184

185185
The example above produced an integer literal using
186-
[`AstBuilder::expr_uint`](../syntax/ext/build/trait.AstBuilder.html#tymethod.expr_uint).
186+
[`AstBuilder::expr_usize`](../syntax/ext/build/trait.AstBuilder.html#tymethod.expr_usize).
187187
As an alternative to the `AstBuilder` trait, `libsyntax` provides a set of
188188
[quasiquote macros](../syntax/ext/quote/index.html). They are undocumented and
189189
very rough around the edges. However, the implementation may be a good

‎src/libsyntax/diagnostics/plugin.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@ use std::collections::BTreeMap;
1414
use ast;
1515
use ast::{Ident, Name, TokenTree};
1616
use codemap::Span;
17-
use ext::base::{ExtCtxt, MacExpr, MacResult, MacItems};
17+
use ext::base::{ExtCtxt, MacEager, MacResult};
1818
use ext::build::AstBuilder;
1919
use parse::token;
2020
use ptr::P;
21+
use util::small_vector::SmallVector;
2122

2223
thread_local! {
2324
static REGISTERED_DIAGNOSTICS: RefCell<BTreeMap<Name, Option<Name>>> = {
@@ -73,7 +74,7 @@ pub fn expand_diagnostic_used<'cx>(ecx: &'cx mut ExtCtxt,
7374
));
7475
}
7576
});
76-
MacExpr::new(quote_expr!(ecx, ()))
77+
MacEager::expr(quote_expr!(ecx, ()))
7778
}
7879

7980
pub fn expand_register_diagnostic<'cx>(ecx: &'cx mut ExtCtxt,
@@ -101,7 +102,7 @@ pub fn expand_register_diagnostic<'cx>(ecx: &'cx mut ExtCtxt,
101102
let sym = Ident::new(token::gensym(&(
102103
"__register_diagnostic_".to_string() + &token::get_ident(*code)
103104
)));
104-
MacItems::new(vec![quote_item!(ecx, mod $sym {}).unwrap()].into_iter())
105+
MacEager::items(SmallVector::many(vec![quote_item!(ecx, mod $sym {}).unwrap()]))
105106
}
106107

107108
pub fn expand_build_diagnostic_array<'cx>(ecx: &'cx mut ExtCtxt,
@@ -126,7 +127,7 @@ pub fn expand_build_diagnostic_array<'cx>(ecx: &'cx mut ExtCtxt,
126127
(descriptions.len(), ecx.expr_vec(span, descriptions))
127128
});
128129

129-
MacItems::new(vec![quote_item!(ecx,
130+
MacEager::items(SmallVector::many(vec![quote_item!(ecx,
130131
pub static $name: [(&'static str, &'static str); $count] = $expr;
131-
).unwrap()].into_iter())
132+
).unwrap()]))
132133
}

‎src/libsyntax/ext/asm.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ pub fn expand_asm<'cx>(cx: &'cx mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
217217
},
218218
});
219219

220-
MacExpr::new(P(ast::Expr {
220+
MacEager::expr(P(ast::Expr {
221221
id: ast::DUMMY_NODE_ID,
222222
node: ast::ExprInlineAsm(ast::InlineAsm {
223223
asm: token::intern_and_get_ident(&asm),

‎src/libsyntax/ext/base.rs

+69-47
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ use fold::Folder;
2828

2929
use std::collections::HashMap;
3030
use std::rc::Rc;
31+
use std::default::Default;
3132

3233
pub trait ItemDecorator {
3334
fn expand(&self,
@@ -226,9 +227,17 @@ impl<F> IdentMacroExpander for F
226227
}
227228
}
228229

230+
// Use a macro because forwarding to a simple function has type system issues
231+
macro_rules! make_stmt_default {
232+
($me:expr) => {
233+
$me.make_expr().map(|e| {
234+
P(codemap::respan(e.span, ast::StmtExpr(e, ast::DUMMY_NODE_ID)))
235+
})
236+
}
237+
}
238+
229239
/// The result of a macro expansion. The return values of the various
230-
/// methods are spliced into the AST at the callsite of the macro (or
231-
/// just into the compiler's internal macro table, for `make_def`).
240+
/// methods are spliced into the AST at the callsite of the macro.
232241
pub trait MacResult {
233242
/// Create an expression.
234243
fn make_expr(self: Box<Self>) -> Option<P<ast::Expr>> {
@@ -254,63 +263,76 @@ pub trait MacResult {
254263
/// By default this attempts to create an expression statement,
255264
/// returning None if that fails.
256265
fn make_stmt(self: Box<Self>) -> Option<P<ast::Stmt>> {
257-
self.make_expr()
258-
.map(|e| P(codemap::respan(e.span, ast::StmtExpr(e, ast::DUMMY_NODE_ID))))
266+
make_stmt_default!(self)
259267
}
260268
}
261269

262-
/// A convenience type for macros that return a single expression.
263-
pub struct MacExpr {
264-
e: P<ast::Expr>
265-
}
266-
impl MacExpr {
267-
pub fn new(e: P<ast::Expr>) -> Box<MacResult+'static> {
268-
box MacExpr { e: e } as Box<MacResult+'static>
269-
}
270-
}
271-
impl MacResult for MacExpr {
272-
fn make_expr(self: Box<MacExpr>) -> Option<P<ast::Expr>> {
273-
Some(self.e)
274-
}
275-
fn make_pat(self: Box<MacExpr>) -> Option<P<ast::Pat>> {
276-
match self.e.node {
277-
ast::ExprLit(_) => Some(P(ast::Pat {
278-
id: ast::DUMMY_NODE_ID,
279-
span: self.e.span,
280-
node: ast::PatLit(self.e)
281-
})),
282-
_ => None
270+
macro_rules! make_MacEager {
271+
( $( $fld:ident: $t:ty, )* ) => {
272+
/// `MacResult` implementation for the common case where you've already
273+
/// built each form of AST that you might return.
274+
#[derive(Default)]
275+
pub struct MacEager {
276+
$(
277+
pub $fld: Option<$t>,
278+
)*
279+
}
280+
281+
impl MacEager {
282+
$(
283+
pub fn $fld(v: $t) -> Box<MacResult> {
284+
box MacEager {
285+
$fld: Some(v),
286+
..Default::default()
287+
} as Box<MacResult>
288+
}
289+
)*
283290
}
284291
}
285292
}
286-
/// A convenience type for macros that return a single pattern.
287-
pub struct MacPat {
288-
p: P<ast::Pat>
293+
294+
make_MacEager! {
295+
expr: P<ast::Expr>,
296+
pat: P<ast::Pat>,
297+
items: SmallVector<P<ast::Item>>,
298+
methods: SmallVector<P<ast::Method>>,
299+
stmt: P<ast::Stmt>,
289300
}
290-
impl MacPat {
291-
pub fn new(p: P<ast::Pat>) -> Box<MacResult+'static> {
292-
box MacPat { p: p } as Box<MacResult+'static>
301+
302+
impl MacResult for MacEager {
303+
fn make_expr(self: Box<Self>) -> Option<P<ast::Expr>> {
304+
self.expr
293305
}
294-
}
295-
impl MacResult for MacPat {
296-
fn make_pat(self: Box<MacPat>) -> Option<P<ast::Pat>> {
297-
Some(self.p)
306+
307+
fn make_items(self: Box<Self>) -> Option<SmallVector<P<ast::Item>>> {
308+
self.items
298309
}
299-
}
300-
/// A type for macros that return multiple items.
301-
pub struct MacItems {
302-
items: SmallVector<P<ast::Item>>
303-
}
304310

305-
impl MacItems {
306-
pub fn new<I: Iterator<Item=P<ast::Item>>>(it: I) -> Box<MacResult+'static> {
307-
box MacItems { items: it.collect() } as Box<MacResult+'static>
311+
fn make_methods(self: Box<Self>) -> Option<SmallVector<P<ast::Method>>> {
312+
self.methods
308313
}
309-
}
310314

311-
impl MacResult for MacItems {
312-
fn make_items(self: Box<MacItems>) -> Option<SmallVector<P<ast::Item>>> {
313-
Some(self.items)
315+
fn make_stmt(self: Box<Self>) -> Option<P<ast::Stmt>> {
316+
match self.stmt {
317+
None => make_stmt_default!(self),
318+
s => s,
319+
}
320+
}
321+
322+
fn make_pat(self: Box<Self>) -> Option<P<ast::Pat>> {
323+
if let Some(p) = self.pat {
324+
return Some(p);
325+
}
326+
if let Some(e) = self.expr {
327+
if let ast::ExprLit(_) = e.node {
328+
return Some(P(ast::Pat {
329+
id: ast::DUMMY_NODE_ID,
330+
span: e.span,
331+
node: ast::PatLit(e),
332+
}));
333+
}
334+
}
335+
None
314336
}
315337
}
316338

‎src/libsyntax/ext/cfg.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,5 @@ pub fn expand_cfg<'cx>(cx: &mut ExtCtxt,
3535
}
3636

3737
let matches_cfg = attr::cfg_matches(&cx.parse_sess.span_diagnostic, &cx.cfg, &*cfg);
38-
MacExpr::new(cx.expr_bool(sp, matches_cfg))
38+
MacEager::expr(cx.expr_bool(sp, matches_cfg))
3939
}

‎src/libsyntax/ext/concat.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ pub fn expand_syntax_ext(cx: &mut base::ExtCtxt,
6060
}
6161
}
6262
}
63-
base::MacExpr::new(cx.expr_str(
63+
base::MacEager::expr(cx.expr_str(
6464
sp,
6565
token::intern_and_get_ident(&accumulator[..])))
6666
}

‎src/libsyntax/ext/concat_idents.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,5 +67,5 @@ pub fn expand_syntax_ext<'cx>(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]
6767
),
6868
span: sp,
6969
});
70-
MacExpr::new(e)
70+
MacEager::expr(e)
7171
}

‎src/libsyntax/ext/env.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ pub fn expand_option_env<'cx>(cx: &'cx mut ExtCtxt, sp: Span, tts: &[ast::TokenT
5959
&s[..]))))
6060
}
6161
};
62-
MacExpr::new(e)
62+
MacEager::expr(e)
6363
}
6464

6565
pub fn expand_env<'cx>(cx: &'cx mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
@@ -108,5 +108,5 @@ pub fn expand_env<'cx>(cx: &'cx mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
108108
}
109109
Ok(s) => cx.expr_str(sp, token::intern_and_get_ident(&s))
110110
};
111-
MacExpr::new(e)
111+
MacEager::expr(e)
112112
}

‎src/libsyntax/ext/format.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,7 @@ pub fn expand_format_args<'cx>(ecx: &'cx mut ExtCtxt, sp: Span,
633633

634634
match parse_args(ecx, sp, tts) {
635635
Some((efmt, args, order, names)) => {
636-
MacExpr::new(expand_preparsed_format_args(ecx, sp, efmt,
636+
MacEager::expr(expand_preparsed_format_args(ecx, sp, efmt,
637637
args, order, names))
638638
}
639639
None => DummyResult::expr(sp)

‎src/libsyntax/ext/quote.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -402,15 +402,15 @@ pub fn expand_quote_tokens<'cx>(cx: &'cx mut ExtCtxt,
402402
-> Box<base::MacResult+'cx> {
403403
let (cx_expr, expr) = expand_tts(cx, sp, tts);
404404
let expanded = expand_wrapper(cx, sp, cx_expr, expr);
405-
base::MacExpr::new(expanded)
405+
base::MacEager::expr(expanded)
406406
}
407407

408408
pub fn expand_quote_expr<'cx>(cx: &'cx mut ExtCtxt,
409409
sp: Span,
410410
tts: &[ast::TokenTree])
411411
-> Box<base::MacResult+'cx> {
412412
let expanded = expand_parse_call(cx, sp, "parse_expr", Vec::new(), tts);
413-
base::MacExpr::new(expanded)
413+
base::MacEager::expr(expanded)
414414
}
415415

416416
pub fn expand_quote_item<'cx>(cx: &mut ExtCtxt,
@@ -419,31 +419,31 @@ pub fn expand_quote_item<'cx>(cx: &mut ExtCtxt,
419419
-> Box<base::MacResult+'cx> {
420420
let expanded = expand_parse_call(cx, sp, "parse_item_with_outer_attributes",
421421
vec!(), tts);
422-
base::MacExpr::new(expanded)
422+
base::MacEager::expr(expanded)
423423
}
424424

425425
pub fn expand_quote_pat<'cx>(cx: &'cx mut ExtCtxt,
426426
sp: Span,
427427
tts: &[ast::TokenTree])
428428
-> Box<base::MacResult+'cx> {
429429
let expanded = expand_parse_call(cx, sp, "parse_pat", vec!(), tts);
430-
base::MacExpr::new(expanded)
430+
base::MacEager::expr(expanded)
431431
}
432432

433433
pub fn expand_quote_arm(cx: &mut ExtCtxt,
434434
sp: Span,
435435
tts: &[ast::TokenTree])
436436
-> Box<base::MacResult+'static> {
437437
let expanded = expand_parse_call(cx, sp, "parse_arm", vec!(), tts);
438-
base::MacExpr::new(expanded)
438+
base::MacEager::expr(expanded)
439439
}
440440

441441
pub fn expand_quote_ty(cx: &mut ExtCtxt,
442442
sp: Span,
443443
tts: &[ast::TokenTree])
444444
-> Box<base::MacResult+'static> {
445445
let expanded = expand_parse_call(cx, sp, "parse_ty", vec!(), tts);
446-
base::MacExpr::new(expanded)
446+
base::MacEager::expr(expanded)
447447
}
448448

449449
pub fn expand_quote_method(cx: &mut ExtCtxt,
@@ -452,7 +452,7 @@ pub fn expand_quote_method(cx: &mut ExtCtxt,
452452
-> Box<base::MacResult+'static> {
453453
let expanded = expand_parse_call(cx, sp, "parse_method_with_outer_attributes",
454454
vec!(), tts);
455-
base::MacExpr::new(expanded)
455+
base::MacEager::expr(expanded)
456456
}
457457

458458
pub fn expand_quote_stmt(cx: &mut ExtCtxt,
@@ -462,7 +462,7 @@ pub fn expand_quote_stmt(cx: &mut ExtCtxt,
462462
let e_attrs = cx.expr_vec_ng(sp);
463463
let expanded = expand_parse_call(cx, sp, "parse_stmt",
464464
vec!(e_attrs), tts);
465-
base::MacExpr::new(expanded)
465+
base::MacEager::expr(expanded)
466466
}
467467

468468
fn ids_ext(strs: Vec<String> ) -> Vec<ast::Ident> {

‎src/libsyntax/ext/source_util.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ pub fn expand_line(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
3535
let topmost = cx.original_span_in_file();
3636
let loc = cx.codemap().lookup_char_pos(topmost.lo);
3737

38-
base::MacExpr::new(cx.expr_u32(topmost, loc.line as u32))
38+
base::MacEager::expr(cx.expr_u32(topmost, loc.line as u32))
3939
}
4040

4141
/* column!(): expands to the current column number */
@@ -46,7 +46,7 @@ pub fn expand_column(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
4646
let topmost = cx.original_span_in_file();
4747
let loc = cx.codemap().lookup_char_pos(topmost.lo);
4848

49-
base::MacExpr::new(cx.expr_u32(topmost, loc.col.to_usize() as u32))
49+
base::MacEager::expr(cx.expr_u32(topmost, loc.col.to_usize() as u32))
5050
}
5151

5252
/// file!(): expands to the current filename */
@@ -59,13 +59,13 @@ pub fn expand_file(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
5959
let topmost = cx.original_span_in_file();
6060
let loc = cx.codemap().lookup_char_pos(topmost.lo);
6161
let filename = token::intern_and_get_ident(&loc.file.name);
62-
base::MacExpr::new(cx.expr_str(topmost, filename))
62+
base::MacEager::expr(cx.expr_str(topmost, filename))
6363
}
6464

6565
pub fn expand_stringify(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
6666
-> Box<base::MacResult+'static> {
6767
let s = pprust::tts_to_string(tts);
68-
base::MacExpr::new(cx.expr_str(sp,
68+
base::MacEager::expr(cx.expr_str(sp,
6969
token::intern_and_get_ident(&s[..])))
7070
}
7171

@@ -77,7 +77,7 @@ pub fn expand_mod(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
7777
.map(|x| token::get_ident(*x).to_string())
7878
.collect::<Vec<String>>()
7979
.connect("::");
80-
base::MacExpr::new(cx.expr_str(
80+
base::MacEager::expr(cx.expr_str(
8181
sp,
8282
token::intern_and_get_ident(&string[..])))
8383
}
@@ -155,7 +155,7 @@ pub fn expand_include_str(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
155155
let interned = token::intern_and_get_ident(&src[..]);
156156
cx.codemap().new_filemap(filename, src);
157157

158-
base::MacExpr::new(cx.expr_str(sp, interned))
158+
base::MacEager::expr(cx.expr_str(sp, interned))
159159
}
160160
Err(_) => {
161161
cx.span_err(sp,
@@ -181,7 +181,7 @@ pub fn expand_include_bytes(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
181181
}
182182
Ok(bytes) => {
183183
let bytes = bytes.iter().cloned().collect();
184-
base::MacExpr::new(cx.expr_lit(sp, ast::LitBinary(Rc::new(bytes))))
184+
base::MacEager::expr(cx.expr_lit(sp, ast::LitBinary(Rc::new(bytes))))
185185
}
186186
}
187187
}

‎src/test/auxiliary/issue_16723_multiple_items_syntax_ext.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ extern crate rustc;
1919

2020
use syntax::ast;
2121
use syntax::codemap;
22-
use syntax::ext::base::{ExtCtxt, MacResult, MacItems};
22+
use syntax::ext::base::{ExtCtxt, MacResult, MacEager};
23+
use syntax::util::small_vector::SmallVector;
2324
use rustc::plugin::Registry;
2425

2526
#[plugin_registrar]
@@ -28,8 +29,8 @@ pub fn plugin_registrar(reg: &mut Registry) {
2829
}
2930

3031
fn expand(cx: &mut ExtCtxt, _: codemap::Span, _: &[ast::TokenTree]) -> Box<MacResult+'static> {
31-
MacItems::new(vec![
32+
MacEager::items(SmallVector::many(vec![
3233
quote_item!(cx, struct Struct1;).unwrap(),
3334
quote_item!(cx, struct Struct2;).unwrap()
34-
].into_iter())
35+
]))
3536
}

‎src/test/auxiliary/macro_crate_test.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ fn expand_make_a_1(cx: &mut ExtCtxt, sp: Span, tts: &[TokenTree])
4747
if !tts.is_empty() {
4848
cx.span_fatal(sp, "make_a_1 takes no arguments");
4949
}
50-
MacExpr::new(quote_expr!(cx, 1))
50+
MacEager::expr(quote_expr!(cx, 1))
5151
}
5252

5353
// See Issue #15750
@@ -57,7 +57,7 @@ fn expand_identity(cx: &mut ExtCtxt, _span: Span, tts: &[TokenTree])
5757
let mut parser = parse::new_parser_from_tts(cx.parse_sess(),
5858
cx.cfg(), tts.to_vec());
5959
let expr = parser.parse_expr();
60-
MacExpr::new(quote_expr!(&mut *cx, $expr))
60+
MacEager::expr(quote_expr!(&mut *cx, $expr))
6161
}
6262

6363
fn expand_into_foo(cx: &mut ExtCtxt, sp: Span, attr: &MetaItem, it: P<Item>)
@@ -114,7 +114,7 @@ fn expand_forged_ident(cx: &mut ExtCtxt, sp: Span, tts: &[TokenTree]) -> Box<Mac
114114
let mut parser = new_parser_from_tts(parse_sess, cfg, tt);
115115
parser.parse_expr()
116116
};
117-
MacExpr::new(expr)
117+
MacEager::expr(expr)
118118
}
119119

120120
pub fn foo() {}

‎src/test/auxiliary/plugin_args.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use std::borrow::ToOwned;
2020
use syntax::ast;
2121
use syntax::codemap::Span;
2222
use syntax::ext::build::AstBuilder;
23-
use syntax::ext::base::{TTMacroExpander, ExtCtxt, MacResult, MacExpr, NormalTT};
23+
use syntax::ext::base::{TTMacroExpander, ExtCtxt, MacResult, MacEager, NormalTT};
2424
use syntax::parse::token;
2525
use syntax::print::pprust;
2626
use syntax::ptr::P;
@@ -38,7 +38,7 @@ impl TTMacroExpander for Expander {
3838
let args = self.args.iter().map(|i| pprust::meta_item_to_string(&*i))
3939
.collect::<Vec<_>>().connect(", ");
4040
let interned = token::intern_and_get_ident(&args[..]);
41-
MacExpr::new(ecx.expr_str(sp, interned))
41+
MacEager::expr(ecx.expr_str(sp, interned))
4242
}
4343
}
4444

‎src/test/auxiliary/roman_numerals.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ extern crate rustc;
1919
use syntax::codemap::Span;
2020
use syntax::parse::token;
2121
use syntax::ast::{TokenTree, TtToken};
22-
use syntax::ext::base::{ExtCtxt, MacResult, DummyResult, MacExpr};
22+
use syntax::ext::base::{ExtCtxt, MacResult, DummyResult, MacEager};
2323
use syntax::ext::build::AstBuilder; // trait for expr_usize
2424
use rustc::plugin::Registry;
2525

@@ -61,7 +61,7 @@ fn expand_rn(cx: &mut ExtCtxt, sp: Span, args: &[TokenTree])
6161
}
6262
}
6363

64-
MacExpr::new(cx.expr_usize(sp, total))
64+
MacEager::expr(cx.expr_usize(sp, total))
6565
}
6666

6767
#[plugin_registrar]

‎src/test/auxiliary/syntax_extension_with_dll_deps_2.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,5 @@ pub fn plugin_registrar(reg: &mut Registry) {
3030
fn expand_foo(cx: &mut ExtCtxt, sp: Span, tts: &[TokenTree])
3131
-> Box<MacResult+'static> {
3232
let answer = other::the_answer();
33-
MacExpr::new(quote_expr!(cx, $answer))
33+
MacEager::expr(quote_expr!(cx, $answer))
3434
}

0 commit comments

Comments
 (0)
Please sign in to comment.