Skip to content

Commit e77491b

Browse files
paulstansifergraydon
authored andcommitted
Make the parser handle stmt macros that might be exprs at the end of blocks.
1 parent bd92499 commit e77491b

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/libsyntax/parse/parser.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2380,6 +2380,25 @@ impl Parser {
23802380
}
23812381
}
23822382

2383+
stmt_mac(m) => {
2384+
// Statement macro; might be an expr
2385+
match self.token {
2386+
token::SEMI => {
2387+
self.bump();
2388+
stmts.push(stmt);
2389+
}
2390+
token::RBRACE => {
2391+
// if a block ends in `m!(arg)` without
2392+
// a `;`, it must be an expr
2393+
expr = Some(
2394+
self.mk_mac_expr(stmt.span.lo,
2395+
stmt.span.hi,
2396+
m.node));
2397+
}
2398+
_ => { stmts.push(stmt); }
2399+
}
2400+
}
2401+
23832402
_ => { // All other kinds of statements:
23842403
stmts.push(stmt);
23852404

@@ -3567,6 +3586,10 @@ impl Parser {
35673586
// item macro.
35683587
let pth = self.parse_path_without_tps();
35693588
self.expect(token::NOT);
3589+
3590+
// a 'special' identifier (like what `macro_rules!` uses)
3591+
// is optional. We should eventually unify invoc syntax
3592+
// and remove this.
35703593
let id = if self.token == token::LPAREN {
35713594
token::special_idents::invalid // no special identifier
35723595
} else {

0 commit comments

Comments
 (0)