Skip to content

Commit 60fa945

Browse files
committed
---
yaml --- r: 7049 b: refs/heads/master c: f832edc h: refs/heads/master i: 7047: e116e83 v: v3
1 parent 3a42bc2 commit 60fa945

File tree

19 files changed

+90
-67
lines changed

19 files changed

+90
-67
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: 37ba5f3b3252aceb28c037021225bbb6a27006f3
2+
refs/heads/master: f832edc369761839f25161df94200b7cce9ddc20

trunk/src/comp/front/test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ fn mk_test_wrapper(cx: test_ctxt,
318318
};
319319

320320
let call_stmt: ast::stmt = nospan(
321-
ast::stmt_expr(@call_expr, cx.sess.next_node_id()));
321+
ast::stmt_semi(@call_expr, cx.sess.next_node_id()));
322322

323323
let wrapper_decl: ast::fn_decl = {
324324
inputs: [],

trunk/src/comp/middle/alias.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ fn visit_block(cx: @ctx, b: ast::blk, sc: scope, v: vt<scope>) {
155155
}
156156
}
157157
}
158-
ast::stmt_expr(ex, _) {
158+
ast::stmt_expr(ex, _) | ast::stmt_semi(ex, _) {
159159
v.visit_expr(ex, sc, v);
160160
}
161161
}

trunk/src/comp/middle/trans.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4053,7 +4053,9 @@ fn trans_stmt(cx: @block_ctxt, s: ast::stmt) -> @block_ctxt {
40534053
debuginfo::update_source_pos(cx, s.span);
40544054

40554055
alt s.node {
4056-
ast::stmt_expr(e, _) { bcx = trans_expr(cx, e, ignore); }
4056+
ast::stmt_expr(e, _) | ast::stmt_semi(e, _) {
4057+
bcx = trans_expr(cx, e, ignore);
4058+
}
40574059
ast::stmt_decl(d, _) {
40584060
alt d.node {
40594061
ast::decl_local(locals) {

trunk/src/comp/middle/tstate/annotate.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,9 @@ fn collect_ids_block(b: blk, rs: @mutable [node_id]) { *rs += [b.node.id]; }
1414

1515
fn collect_ids_stmt(s: @stmt, rs: @mutable [node_id]) {
1616
alt s.node {
17-
stmt_decl(_, id) {
17+
stmt_decl(_, id) | stmt_expr(_, id) | stmt_semi(_, id) {
1818
log(debug, "node_id " + int::str(id));
19-
log_stmt(*s);;
20-
*rs += [id];
21-
}
22-
stmt_expr(_, id) {
23-
log(debug, "node_id " + int::str(id));
24-
log_stmt(*s);;
19+
log_stmt(*s);
2520
*rs += [id];
2621
}
2722
_ { }

trunk/src/comp/middle/tstate/auxiliary.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -324,8 +324,9 @@ fn node_id_to_poststate(ccx: crate_ctxt, id: node_id) -> poststate {
324324
fn stmt_to_ann(ccx: crate_ctxt, s: stmt) -> ts_ann {
325325
#debug("stmt_to_ann");
326326
alt s.node {
327-
stmt_decl(_, id) { ret node_id_to_ts_ann(ccx, id); }
328-
stmt_expr(_, id) { ret node_id_to_ts_ann(ccx, id); }
327+
stmt_decl(_, id) | stmt_expr(_, id) | stmt_semi(_, id) {
328+
ret node_id_to_ts_ann(ccx, id);
329+
}
329330
}
330331
}
331332

trunk/src/comp/middle/tstate/pre_post_conditions.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,7 @@ fn find_pre_post_stmt(fcx: fn_ctxt, s: stmt) {
647647
}
648648
}
649649
}
650-
stmt_expr(e, id) {
650+
stmt_expr(e, id) | stmt_semi(e, id) {
651651
find_pre_post_expr(fcx, e);
652652
copy_pre_post(fcx.ccx, id, e);
653653
}

trunk/src/comp/middle/tstate/states.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,7 @@ fn find_pre_post_state_stmt(fcx: fn_ctxt, pres: prestate, s: @stmt) -> bool {
664664
}
665665
}
666666
}
667-
stmt_expr(ex, _) {
667+
stmt_expr(ex, _) | stmt_semi(ex, _) {
668668
let changed =
669669
find_pre_post_state_expr(fcx, pres, ex) |
670670
set_prestate(stmt_ann, expr_prestate(fcx.ccx, ex)) |

trunk/src/comp/middle/ty.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1660,8 +1660,9 @@ fn expr_is_lval(method_map: typeck::method_map, tcx: ty::ctxt,
16601660

16611661
fn stmt_node_id(s: @ast::stmt) -> ast::node_id {
16621662
alt s.node {
1663-
ast::stmt_decl(_, id) { ret id; }
1664-
ast::stmt_expr(_, id) { ret id; }
1663+
ast::stmt_decl(_, id) | stmt_expr(_, id) | stmt_semi(_, id) {
1664+
ret id;
1665+
}
16651666
}
16661667
}
16671668

trunk/src/comp/middle/typeck.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2539,7 +2539,14 @@ fn check_stmt(fcx: @fn_ctxt, stmt: @ast::stmt) -> bool {
25392539
ast::decl_item(_) {/* ignore for now */ }
25402540
}
25412541
}
2542-
ast::stmt_expr(expr, id) { node_id = id; bot = check_expr(fcx, expr); }
2542+
ast::stmt_expr(expr, id) {
2543+
node_id = id;
2544+
bot = check_expr_with(fcx, expr, ty::mk_nil(fcx.ccx.tcx));
2545+
}
2546+
ast::stmt_semi(expr, id) {
2547+
node_id = id;
2548+
bot = check_expr(fcx, expr);
2549+
}
25432550
}
25442551
write::nil_ty(fcx.ccx.tcx, node_id);
25452552
ret bot;
@@ -2567,7 +2574,7 @@ fn check_block(fcx0: @fn_ctxt, blk: ast::blk) -> bool {
25672574
if bot && !warned &&
25682575
alt s.node {
25692576
ast::stmt_decl(@{node: ast::decl_local(_), _}, _) |
2570-
ast::stmt_expr(_, _) {
2577+
ast::stmt_expr(_, _) | ast::stmt_semi(_, _) {
25712578
true
25722579
}
25732580
_ { false }

trunk/src/comp/syntax/ast.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,12 @@ type stmt = spanned<stmt_>;
156156

157157
tag stmt_ {
158158
stmt_decl(@decl, node_id);
159+
160+
// expr without trailing semi-colon (must have unit type):
159161
stmt_expr(@expr, node_id);
162+
163+
// expr with trailing semi-colon (may have any type):
164+
stmt_semi(@expr, node_id);
160165
}
161166

162167
tag init_op { init_assign; init_move; }

trunk/src/comp/syntax/fold.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,8 +272,9 @@ fn noop_fold_block(b: blk_, fld: ast_fold) -> blk_ {
272272

273273
fn noop_fold_stmt(s: stmt_, fld: ast_fold) -> stmt_ {
274274
ret alt s {
275-
stmt_decl(d, nid) { stmt_decl(fld.fold_decl(d), nid) }
276-
stmt_expr(e, nid) { stmt_expr(fld.fold_expr(e), nid) }
275+
stmt_decl(d, nid) { stmt_decl(fld.fold_decl(d), nid) }
276+
stmt_expr(e, nid) { stmt_expr(fld.fold_expr(e), nid) }
277+
stmt_semi(e, nid) { stmt_semi(fld.fold_expr(e), nid) }
277278
};
278279
}
279280

trunk/src/comp/syntax/parse/parser.rs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1639,13 +1639,6 @@ fn expr_requires_semi_to_be_stmt(e: @ast::expr) -> bool {
16391639
}
16401640
}
16411641

1642-
fn stmt_to_expr(stmt: @ast::stmt) -> option::t<@ast::expr> {
1643-
alt stmt.node {
1644-
ast::stmt_expr(e, _) { some(e) }
1645-
_ { none }
1646-
}
1647-
}
1648-
16491642
fn stmt_ends_with_semi(stmt: ast::stmt) -> bool {
16501643
alt stmt.node {
16511644
ast::stmt_decl(d, _) {
@@ -1657,6 +1650,9 @@ fn stmt_ends_with_semi(stmt: ast::stmt) -> bool {
16571650
ast::stmt_expr(e, _) {
16581651
ret expr_requires_semi_to_be_stmt(e);
16591652
}
1653+
ast::stmt_semi(e, _) {
1654+
ret false;
1655+
}
16601656
}
16611657
}
16621658

@@ -1695,11 +1691,16 @@ fn parse_block_tail(p: parser, lo: uint, s: ast::blk_check_mode) -> ast::blk {
16951691
}
16961692
_ {
16971693
let stmt = parse_stmt(p);
1698-
alt stmt_to_expr(stmt) {
1699-
some(e) {
1694+
alt stmt.node {
1695+
ast::stmt_expr(e, stmt_id) { // Expression without semicolon:
17001696
alt p.peek() {
1701-
token::SEMI. { p.bump(); stmts += [stmt]; }
1702-
token::RBRACE. { expr = some(e); }
1697+
token::SEMI. {
1698+
p.bump();
1699+
stmts += [@{node: ast::stmt_semi(e, stmt_id) with *stmt}];
1700+
}
1701+
token::RBRACE. {
1702+
expr = some(e);
1703+
}
17031704
t {
17041705
if stmt_ends_with_semi(*stmt) {
17051706
p.fatal("expected ';' or '}' after expression but \
@@ -1710,8 +1711,8 @@ fn parse_block_tail(p: parser, lo: uint, s: ast::blk_check_mode) -> ast::blk {
17101711
}
17111712
}
17121713
}
1713-
none. {
1714-
// Not an expression statement.
1714+
1715+
_ { // All other kinds of statements:
17151716
stmts += [stmt];
17161717

17171718
if stmt_ends_with_semi(*stmt) {

trunk/src/comp/syntax/print/pprust.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,11 @@ fn print_stmt(s: ps, st: ast::stmt) {
569569
space_if_not_bol(s);
570570
print_tl_expr(s, expr);
571571
}
572+
ast::stmt_semi(expr, _) {
573+
space_if_not_bol(s);
574+
print_tl_expr(s, expr);
575+
word(s.s, ";");
576+
}
572577
}
573578
if parse::parser::stmt_ends_with_semi(st) { word(s.s, ";"); }
574579
maybe_print_trailing_comment(s, st.span, none::<uint>);

trunk/src/comp/syntax/visit.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ fn visit_stmt<E>(s: @stmt, e: E, v: vt<E>) {
262262
alt s.node {
263263
stmt_decl(d, _) { v.visit_decl(d, e, v); }
264264
stmt_expr(ex, _) { v.visit_expr(ex, e, v); }
265+
stmt_semi(ex, _) { v.visit_expr(ex, e, v); }
265266
}
266267
}
267268

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
fn compute1() -> float {
3+
let v = [0f, 1f, 2f, 3f];
4+
5+
vec::foldl(0f, v) { |x, y| x + y } - 10f
6+
//!^ ERROR mismatched types: expected `()`
7+
}
8+
9+
fn main() {
10+
let x = compute1();
11+
log(debug, x);
12+
assert(y == -4f);
13+
}

trunk/src/test/run-pass/block-arg-as-stmt.rs

Lines changed: 0 additions & 25 deletions
This file was deleted.
Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,26 @@
11
fn w_semi(v: [int]) -> int {
2+
// the semicolon causes compiler not to
3+
// complain about the ignored return value:
24
vec::foldl(0, v) {|x,y| x+y};
35
-10
46
}
57

6-
fn wo_paren(v: [int]) -> int {
7-
// Perhaps surprising: this is parsed equivalently to w_semi()
8-
vec::foldl(0, v) {|x,y| x+y} - 10
8+
fn w_paren1(v: [int]) -> int {
9+
(vec::foldl(0, v) {|x,y| x+y}) - 10
910
}
1011

11-
fn w_paren(v: [int]) -> int {
12-
// Here the parentheses force interpretation as an expression:
13-
(vec::foldl(0, v) {|x,y| x+y}) - 10
12+
fn w_paren2(v: [int]) -> int {
13+
(vec::foldl(0, v) {|x,y| x+y} - 10)
14+
}
15+
16+
fn w_ret(v: [int]) -> int {
17+
ret vec::foldl(0, v) {|x,y| x+y} - 10;
1418
}
1519

1620
fn main() {
17-
assert wo_paren([0, 1, 2, 3]) == -10;
1821
assert w_semi([0, 1, 2, 3]) == -10;
19-
assert w_paren([0, 1, 2, 3]) == -4;
22+
assert w_paren1([0, 1, 2, 3]) == -4;
23+
assert w_paren2([0, 1, 2, 3]) == -4;
24+
assert w_ret([0, 1, 2, 3]) == -4;
2025
}
2126

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Make sure #1399 stays fixed
2+
3+
fn foo() -> lambda() -> int {
4+
let k = ~22;
5+
let _u = {a: k};
6+
ret lambda[move k]() -> int { 22 };
7+
}
8+
9+
fn main() {
10+
assert foo()() == 22;
11+
}

0 commit comments

Comments
 (0)