diff options
| author | Brian Anderson <banderson@mozilla.com> | 2012-07-03 17:30:25 -0700 |
|---|---|---|
| committer | Brian Anderson <banderson@mozilla.com> | 2012-07-03 17:30:25 -0700 |
| commit | ae6ea068a12877742247b848ceeaa39c41e981c6 (patch) | |
| tree | 8c146d3fa5668113d192a9ef203e88107c637f23 /src/libsyntax | |
| parent | e000d1db0ab047b8d2949de4ab221718905ce3b1 (diff) | |
| download | rust-ae6ea068a12877742247b848ceeaa39c41e981c6.tar.gz rust-ae6ea068a12877742247b848ceeaa39c41e981c6.zip | |
Revert "Remove rule requiring non-nil block-style statements to be semi-terminated"
This reverts commit 0f5eaef5fb2443acd3ea67250c953839c3d04d38.
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/ast.rs | 5 | ||||
| -rw-r--r-- | src/libsyntax/ast_util.rs | 1 | ||||
| -rw-r--r-- | src/libsyntax/ext/auto_serialize.rs | 2 | ||||
| -rw-r--r-- | src/libsyntax/fold.rs | 1 | ||||
| -rw-r--r-- | src/libsyntax/parse/classify.rs | 3 | ||||
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 2 | ||||
| -rw-r--r-- | src/libsyntax/print/pprust.rs | 8 | ||||
| -rw-r--r-- | src/libsyntax/visit.rs | 1 |
8 files changed, 18 insertions, 5 deletions
diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 6c0b5a2e8b1..9419b9f647e 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -243,7 +243,12 @@ type stmt = spanned<stmt_>; #[auto_serialize] enum stmt_ { stmt_decl(@decl, node_id), + + // expr without trailing semi-colon (must have unit type): stmt_expr(@expr, node_id), + + // expr with trailing semi-colon (may have any type): + stmt_semi(@expr, node_id), } #[auto_serialize] diff --git a/src/libsyntax/ast_util.rs b/src/libsyntax/ast_util.rs index 568f00b0dfb..c6fb9349ad5 100644 --- a/src/libsyntax/ast_util.rs +++ b/src/libsyntax/ast_util.rs @@ -38,6 +38,7 @@ pure fn stmt_id(s: stmt) -> node_id { alt s.node { stmt_decl(_, id) { id } stmt_expr(_, id) { id } + stmt_semi(_, id) { id } } } diff --git a/src/libsyntax/ext/auto_serialize.rs b/src/libsyntax/ext/auto_serialize.rs index 8685bce4c1b..d2d685f8f7d 100644 --- a/src/libsyntax/ext/auto_serialize.rs +++ b/src/libsyntax/ext/auto_serialize.rs @@ -206,7 +206,7 @@ impl helpers for ext_ctxt { } fn stmt(expr: @ast::expr) -> @ast::stmt { - @{node: ast::stmt_expr(expr, self.next_id()), + @{node: ast::stmt_semi(expr, self.next_id()), span: expr.span} } diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index fd17403b695..c949c2e17aa 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -315,6 +315,7 @@ fn noop_fold_stmt(s: stmt_, fld: ast_fold) -> stmt_ { ret alt s { stmt_decl(d, nid) { stmt_decl(fld.fold_decl(d), fld.new_id(nid)) } stmt_expr(e, nid) { stmt_expr(fld.fold_expr(e), fld.new_id(nid)) } + stmt_semi(e, nid) { stmt_semi(fld.fold_expr(e), fld.new_id(nid)) } }; } diff --git a/src/libsyntax/parse/classify.rs b/src/libsyntax/parse/classify.rs index 4fcb761fa06..9b36b77407e 100644 --- a/src/libsyntax/parse/classify.rs +++ b/src/libsyntax/parse/classify.rs @@ -27,6 +27,9 @@ fn stmt_ends_with_semi(stmt: ast::stmt) -> bool { ast::stmt_expr(e, _) { ret expr_requires_semi_to_be_stmt(e); } + ast::stmt_semi(e, _) { + ret false; + } } } diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 97185b6dfb9..747ca07bee5 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -1848,7 +1848,7 @@ class parser { token::SEMI { self.bump(); push(stmts, - @{node: stmt_expr(e, stmt_id) with *stmt}); + @{node: stmt_semi(e, stmt_id) with *stmt}); } token::RBRACE { expr = some(e); diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 171ad240635..5f2aada9fc6 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -682,9 +682,11 @@ fn print_stmt(s: ps, st: ast::stmt) { ast::stmt_expr(expr, _) { space_if_not_bol(s); print_expr(s, expr); - if expr_requires_semi_to_be_stmt(expr) { - word(s.s, ";"); - } + } + ast::stmt_semi(expr, _) { + space_if_not_bol(s); + print_expr(s, expr); + word(s.s, ";"); } } if parse::classify::stmt_ends_with_semi(st) { word(s.s, ";"); } diff --git a/src/libsyntax/visit.rs b/src/libsyntax/visit.rs index d2e5b1d1f21..48f2e57de1c 100644 --- a/src/libsyntax/visit.rs +++ b/src/libsyntax/visit.rs @@ -320,6 +320,7 @@ fn visit_stmt<E>(s: @stmt, e: E, v: vt<E>) { alt s.node { stmt_decl(d, _) { v.visit_decl(d, e, v); } stmt_expr(ex, _) { v.visit_expr(ex, e, v); } + stmt_semi(ex, _) { v.visit_expr(ex, e, v); } } } |
