Skip to content

Commit 6174a30

Browse files
paulstansifergraydon
authored andcommitted
Respect semicolons always when expanding statments.
1 parent e7f07cb commit 6174a30

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

src/libsyntax/ext/expand.rs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::map::HashMap;
22

33
use ast::{crate, expr_, expr_mac, mac_invoc, mac_invoc_tt,
4-
tt_delim, tt_tok, item_mac, stmt_, stmt_mac};
4+
tt_delim, tt_tok, item_mac, stmt_, stmt_mac, stmt_expr, stmt_semi};
55
use fold::*;
66
use ext::base::*;
77
use ext::qquote::{qq_helper};
@@ -281,16 +281,14 @@ fn expand_stmt(exts: HashMap<~str, syntax_extension>, cx: ext_ctxt,
281281
282282
assert(vec::len(pth.idents) == 1u);
283283
let extname = cx.parse_sess().interner.get(pth.idents[0]);
284-
match exts.find(*extname) {
284+
let (fully_expanded, sp) = match exts.find(*extname) {
285285
None =>
286286
cx.span_fatal(pth.span, fmt!("macro undefined: '%s'", *extname)),
287287
288288
Some(normal_tt({expander: exp, span: exp_sp})) => {
289289
let expanded = match exp(cx, mac.span, tts) {
290-
mr_expr(e) if !semi =>
291-
@{node: ast::stmt_expr(e, cx.next_id()), span: e.span},
292-
mr_expr(e) if semi =>
293-
@{node: ast::stmt_semi(e, cx.next_id()), span: e.span},
290+
mr_expr(e) =>
291+
@{node: stmt_expr(e, cx.next_id()), span: e.span},
294292
mr_any(_,_,stmt_mkr) => stmt_mkr(),
295293
_ => cx.span_fatal(
296294
pth.span,
@@ -303,14 +301,14 @@ fn expand_stmt(exts: HashMap<~str, syntax_extension>, cx: ext_ctxt,
303301
let fully_expanded = fld.fold_stmt(expanded).node;
304302
cx.bt_pop();
305303
306-
return (fully_expanded, sp)
304+
(fully_expanded, sp)
307305
}
308306
309307
Some(normal({expander: exp, span: exp_sp})) => {
310308
//convert the new-style invoc for the old-style macro
311309
let arg = base::tt_args_to_original_flavor(cx, pth.span, tts);
312310
let exp_expr = exp(cx, mac.span, arg, None);
313-
let expanded = @{node: ast::stmt_expr(exp_expr, cx.next_id()),
311+
let expanded = @{node: stmt_expr(exp_expr, cx.next_id()),
314312
span: exp_expr.span};
315313
316314
cx.bt_push(ExpandedFrom({call_site: sp,
@@ -325,10 +323,14 @@ fn expand_stmt(exts: HashMap<~str, syntax_extension>, cx: ext_ctxt,
325323
326324
_ => {
327325
cx.span_fatal(pth.span,
328-
fmt!("'%s' is not a tt-style macro",
329-
*extname))
326+
fmt!("'%s' is not a tt-style macro", *extname))
330327
}
331-
}
328+
};
329+
330+
return (match fully_expanded {
331+
stmt_expr(e, stmt_id) if semi => stmt_semi(e, stmt_id),
332+
_ => { fully_expanded } /* might already have a semi */
333+
}, sp)
332334
333335
}
334336

0 commit comments

Comments
 (0)