Skip to content

Commit 0f707f4

Browse files
paulstansifergraydon
authored andcommitted
Distinguish stmt_macs that are followed by semicolons and those that aren't.
1 parent e77491b commit 0f707f4

File tree

7 files changed

+17
-12
lines changed

7 files changed

+17
-12
lines changed

src/libsyntax/ast.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -666,7 +666,8 @@ enum stmt_ {
666666
// expr with trailing semi-colon (may have any type):
667667
stmt_semi(@expr, node_id),
668668

669-
stmt_mac(mac),
669+
// bool: is there a trailing sem-colon?
670+
stmt_mac(mac, bool),
670671
}
671672

672673
// FIXME (pending discussion of #1697, #2178...): local should really be

src/libsyntax/ast_util.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ pure fn stmt_id(s: stmt) -> node_id {
4040
stmt_decl(_, id) => id,
4141
stmt_expr(_, id) => id,
4242
stmt_semi(_, id) => id,
43-
stmt_mac(_) => fail ~"attempted to analyze unexpanded stmt",
43+
stmt_mac(*) => fail ~"attempted to analyze unexpanded stmt",
4444
}
4545
}
4646

src/libsyntax/ext/expand.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -272,12 +272,12 @@ fn expand_stmt(exts: HashMap<~str, syntax_extension>, cx: ext_ctxt,
272272
orig: fn@(&&s: stmt_, span, ast_fold) -> (stmt_, span))
273273
-> (stmt_, span)
274274
{
275-
let (mac, pth, tts) = biased_match! (
276-
(s) ~ (stmt_mac(mac)) else return orig(s, sp, fld);
275+
let (mac, pth, tts, semi) = biased_match! (
276+
(s) ~ (stmt_mac(mac, semi)) else return orig(s, sp, fld);
277277
(mac.node) ~ (mac_invoc_tt(pth, tts)) else {
278278
cx.span_bug(mac.span, ~"naked syntactic bit")
279279
};
280-
=> (mac, pth, tts));
280+
=> (mac, pth, tts, semi));
281281
282282
assert(vec::len(pth.idents) == 1u);
283283
let extname = cx.parse_sess().interner.get(pth.idents[0]);
@@ -287,8 +287,10 @@ fn expand_stmt(exts: HashMap<~str, syntax_extension>, cx: ext_ctxt,
287287
288288
Some(normal_tt({expander: exp, span: exp_sp})) => {
289289
let expanded = match exp(cx, mac.span, tts) {
290-
mr_expr(e) =>
290+
mr_expr(e) if !semi =>
291291
@{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},
292294
mr_any(_,_,stmt_mkr) => stmt_mkr(),
293295
_ => cx.span_fatal(
294296
pth.span,

src/libsyntax/fold.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ fn noop_fold_stmt(s: stmt_, fld: ast_fold) -> stmt_ {
310310
stmt_decl(d, nid) => stmt_decl(fld.fold_decl(d), fld.new_id(nid)),
311311
stmt_expr(e, nid) => stmt_expr(fld.fold_expr(e), fld.new_id(nid)),
312312
stmt_semi(e, nid) => stmt_semi(fld.fold_expr(e), fld.new_id(nid)),
313-
stmt_mac(mac) => stmt_mac(fold_mac(mac))
313+
stmt_mac(mac, semi) => stmt_mac(fold_mac(mac), semi)
314314
};
315315
}
316316

src/libsyntax/parse/parser.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2228,7 +2228,7 @@ impl Parser {
22282228
22292229
if id == token::special_idents::invalid {
22302230
return @spanned(lo, hi, stmt_mac(
2231-
spanned(lo, hi, mac_invoc_tt(pth, tts))));
2231+
spanned(lo, hi, mac_invoc_tt(pth, tts)), false));
22322232
} else {
22332233
// if it has a special ident, it's definitely an item
22342234
return @spanned(lo, hi, stmt_decl(
@@ -2380,12 +2380,13 @@ impl Parser {
23802380
}
23812381
}
23822382

2383-
stmt_mac(m) => {
2383+
stmt_mac(m, false) => {
23842384
// Statement macro; might be an expr
23852385
match self.token {
23862386
token::SEMI => {
23872387
self.bump();
2388-
stmts.push(stmt);
2388+
stmts.push(@{node: stmt_mac(m, true),
2389+
..*stmt});
23892390
}
23902391
token::RBRACE => {
23912392
// if a block ends in `m!(arg)` without

src/libsyntax/print/pprust.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -882,9 +882,10 @@ fn print_stmt(s: ps, st: ast::stmt) {
882882
print_expr(s, expr);
883883
word(s.s, ~";");
884884
}
885-
ast::stmt_mac(mac) => {
885+
ast::stmt_mac(mac, semi) => {
886886
space_if_not_bol(s);
887887
print_mac(s, mac);
888+
if semi { word(s.s, ~";"); }
888889
}
889890
}
890891
if parse::classify::stmt_ends_with_semi(st) { word(s.s, ~";"); }

src/libsyntax/visit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ fn visit_stmt<E>(s: @stmt, e: E, v: vt<E>) {
348348
stmt_decl(d, _) => v.visit_decl(d, e, v),
349349
stmt_expr(ex, _) => v.visit_expr(ex, e, v),
350350
stmt_semi(ex, _) => v.visit_expr(ex, e, v),
351-
stmt_mac(mac) => visit_mac(mac, e, v)
351+
stmt_mac(mac, _) => visit_mac(mac, e, v)
352352
}
353353
}
354354

0 commit comments

Comments
 (0)