Skip to content

Commit 978ca03

Browse files
committed
Revert "accept naked exprs with commas in pattern arms" due to pretty-printing failures
This reverts commit f712b2d. In alt arms, the parser needs to do a little lookahead to determine whether it's looking at a record literal or a block. Also there are some indentation issues in the expected source.
1 parent 00aa5f1 commit 978ca03

File tree

6 files changed

+6
-76
lines changed

6 files changed

+6
-76
lines changed

src/libsyntax/ast_util.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -568,13 +568,6 @@ fn view_path_id(p: @view_path) -> node_id {
568568
}
569569
}
570570

571-
fn lone_block_expr(blk: blk) -> option<@ast::expr> {
572-
if blk.node.view_items.len() != 0 { ret none; }
573-
if blk.node.stmts.len() != 0 { ret none; }
574-
if blk.node.rules != default_blk { ret none; }
575-
ret blk.node.expr;
576-
}
577-
578571
// Local Variables:
579572
// mode: rust
580573
// fill-column: 78;

src/libsyntax/parse/parser.rs

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1509,25 +1509,8 @@ class parser {
15091509
let pats = self.parse_pats();
15101510
let mut guard = none;
15111511
if self.eat_keyword(~"if") { guard = some(self.parse_expr()); }
1512-
let blk = if self.token != token::FAT_ARROW {
1513-
self.parse_block()
1514-
} else {
1515-
self.bump();
1516-
if self.token == token::LBRACE {
1517-
self.parse_block()
1518-
} else {
1519-
let expr = self.parse_expr();
1520-
if self.token != token::RBRACE {
1521-
self.expect(token::COMMA);
1522-
}
1523-
{node: {view_items: ~[],
1524-
stmts: ~[],
1525-
expr: some(expr),
1526-
id: self.get_id(),
1527-
rules: default_blk},
1528-
span: expr.span}
1529-
}
1530-
};
1512+
if self.token == token::FAT_ARROW { self.bump(); }
1513+
let blk = self.parse_block();
15311514
vec::push(arms, {pats: pats, guard: guard, body: blk});
15321515
}
15331516
let mut hi = self.span.hi;

src/libsyntax/print/pprust.rs

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import pp::{break_offset, word, printer,
66
inconsistent, eof};
77
import diagnostic;
88
import ast::{required, provided};
9-
import ast_util::{operator_prec, lone_block_expr};
9+
import ast_util::operator_prec;
1010
import dvec::{dvec, extensions};
1111
import parse::classify::*;
1212

@@ -998,8 +998,7 @@ fn print_expr(s: ps, &&expr: @ast::expr) {
998998
print_maybe_parens_discrim(s, expr);
999999
space(s.s);
10001000
bopen(s);
1001-
let len = arms.len();
1002-
for arms.eachi |i, arm| {
1001+
for arms.each |arm| {
10031002
space(s.s);
10041003
cbox(s, alt_indent_unit);
10051004
ibox(s, 0u);
@@ -1015,19 +1014,8 @@ fn print_expr(s: ps, &&expr: @ast::expr) {
10151014
some(e) { word_space(s, ~"if"); print_expr(s, e); space(s.s); }
10161015
none { }
10171016
}
1018-
word_space(s, ~"=>");
1019-
alt lone_block_expr(arm.body) {
1020-
some(expr) => {
1021-
end(s); // close the ibox for the pattern
1022-
print_expr(s, expr);
1023-
if i < len - 1 { word_space(s, ~","); }
1024-
end(s); // close enclosing cbox
1025-
}
1026-
none => {
1027-
print_possibly_embedded_block(s, arm.body, block_normal,
1028-
alt_indent_unit);
1029-
}
1030-
}
1017+
print_possibly_embedded_block(s, arm.body, block_normal,
1018+
alt_indent_unit);
10311019
}
10321020
bclose_(s, expr.span, alt_indent_unit);
10331021
}

src/test/pretty/alt-naked-expr-long.rs

Lines changed: 0 additions & 17 deletions
This file was deleted.

src/test/pretty/alt-naked-expr-medium.rs

Lines changed: 0 additions & 10 deletions
This file was deleted.

src/test/pretty/alt-naked-expr.rs

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)