Skip to content

Commit ba354b1

Browse files
paulstansifergraydon
authored andcommitted
Allow the expansion of old-style expr macros in stmt position.
1 parent b7fcc9b commit ba354b1

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/libsyntax/ext/expand.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,24 @@ fn expand_stmt(exts: HashMap<~str, syntax_extension>, cx: ext_ctxt,
303303
304304
return (fully_expanded, sp)
305305
}
306+
307+
Some(normal({expander: exp, span: exp_sp})) => {
308+
//convert the new-style invoc for the old-style macro
309+
let arg = base::tt_args_to_original_flavor(cx, pth.span, tts);
310+
let exp_expr = exp(cx, mac.span, arg, None);
311+
let expanded = @{node: ast::stmt_expr(exp_expr, cx.next_id()),
312+
span: exp_expr.span};
313+
314+
cx.bt_push(ExpandedFrom({call_site: sp,
315+
callie: {name: *extname,
316+
span: exp_sp}}));
317+
//keep going, outside-in
318+
let fully_expanded = fld.fold_stmt(expanded).node;
319+
cx.bt_pop();
320+
321+
(fully_expanded, sp)
322+
}
323+
306324
_ => {
307325
cx.span_fatal(pth.span,
308326
fmt!("'%s' is not a tt-style macro",

0 commit comments

Comments
 (0)