Skip to content

Commit 8e00161

Browse files
committed
Make the pretty printer disambiguatae blocks followed by vec expressions.
Semicolons are needed here now that postfix [] is used for vec indexing (the syntax change made in rev 518dc52).
1 parent ce432d4 commit 8e00161

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/comp/syntax/print/pprust.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -612,8 +612,9 @@ fn print_possibly_embedded_block(s: &ps, blk: &ast::blk, embedded: embed_type,
612612
tag expr_or_stmt { stmt_(@ast::stmt); expr_(@ast::expr); }
613613

614614
// The Rust syntax has an ambiguity when an if, alt, or block statement is
615-
// followed by a unary op or paren. In those cases we have to add an
616-
// extra semi to make sure the output retains the same meaning.
615+
// followed by a unary op, square bracket, or paren. In those cases we
616+
// have to add an extra semi to make sure the output retains the same
617+
// meaning.
617618
fn maybe_protect_block(s: &ps, last: &option::t<@ast::stmt>,
618619
next: &expr_or_stmt) {
619620
let last_expr_is_block =
@@ -684,6 +685,7 @@ fn print_possibly_embedded_block(s: &ps, blk: &ast::blk, embedded: embed_type,
684685
alt ex.node {
685686
ast::expr_unary(_, _) { true }
686687
ast::expr_tup(_) { true }
688+
ast::expr_vec(_, _) { true }
687689
_ { false }
688690
}
689691
}

src/test/pretty/block-disambig.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,5 @@ fn test10() -> int {
3131
alt true { true { } };
3232
(*regs)[0]
3333
}
34+
35+
fn test11() -> [int] { if true { }; [1, 2] }

0 commit comments

Comments
 (0)