diff --git a/src/comp/front/test.rs b/src/comp/front/test.rs index fcef6e551f12..70985f108060 100644 --- a/src/comp/front/test.rs +++ b/src/comp/front/test.rs @@ -184,7 +184,7 @@ fn mk_tests(cx: test_ctxt) -> @ast::item { let test_descs = mk_test_desc_vec(cx); let body_: ast::blk_ = - checked_block([], option::some(test_descs), cx.next_node_id()); + default_block([], option::some(test_descs), cx.next_node_id()); let body = nospan(body_); let fn_ = {decl: decl, proto: proto, body: body}; @@ -303,7 +303,7 @@ fn mk_main(cx: test_ctxt) -> @ast::item { let test_main_call_expr = mk_test_main_call(cx); let body_: ast::blk_ = - checked_block([], option::some(test_main_call_expr), + default_block([], option::some(test_main_call_expr), cx.next_node_id()); let body = {node: body_, span: dummy_sp()}; diff --git a/src/comp/middle/typeck.rs b/src/comp/middle/typeck.rs index 838b1f674fbf..ec7c2537874e 100644 --- a/src/comp/middle/typeck.rs +++ b/src/comp/middle/typeck.rs @@ -2090,13 +2090,7 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, expr: @ast::expr, unify: unifier, } ast::expr_block(b) { // If this is an unchecked block, turn off purity-checking - let fcx_for_block = - alt b.node.rules { - ast::unchecked_blk. { @{purity: ast::impure_fn with *fcx} } - ast::unsafe_blk. { @{purity: ast::unsafe_fn with *fcx} } - ast::checked_blk. { fcx } - }; - bot = check_block(fcx_for_block, b); + bot = check_block(fcx, b); let typ = alt b.node.expr { some(expr) { expr_ty(tcx, expr) } @@ -2553,7 +2547,12 @@ fn check_stmt(fcx: @fn_ctxt, stmt: @ast::stmt) -> bool { ret bot; } -fn check_block(fcx: @fn_ctxt, blk: ast::blk) -> bool { +fn check_block(fcx0: @fn_ctxt, blk: ast::blk) -> bool { + let fcx = alt blk.node.rules { + ast::unchecked_blk. { @{purity: ast::impure_fn with *fcx0} } + ast::unsafe_blk. { @{purity: ast::unsafe_fn with *fcx0} } + ast::default_blk. { fcx0 } + }; let bot = false; let warned = false; for s: @ast::stmt in blk.node.stmts { diff --git a/src/comp/syntax/ast.rs b/src/comp/syntax/ast.rs index 6b72a4b67c37..d9b5365db5fd 100644 --- a/src/comp/syntax/ast.rs +++ b/src/comp/syntax/ast.rs @@ -174,7 +174,7 @@ type field_ = {mut: mutability, ident: ident, expr: @expr}; type field = spanned; -tag blk_check_mode { checked_blk; unchecked_blk; unsafe_blk; } +tag blk_check_mode { default_blk; unchecked_blk; unsafe_blk; } tag expr_check_mode { claimed_expr; checked_expr; } diff --git a/src/comp/syntax/ast_util.rs b/src/comp/syntax/ast_util.rs index 5d2a143a946a..32c381d90901 100644 --- a/src/comp/syntax/ast_util.rs +++ b/src/comp/syntax/ast_util.rs @@ -185,13 +185,13 @@ fn eq_ty(&&a: @ty, &&b: @ty) -> bool { ret std::box::ptr_eq(a, b); } fn hash_ty(&&t: @ty) -> uint { ret t.span.lo << 16u + t.span.hi; } fn block_from_expr(e: @expr) -> blk { - let blk_ = checked_block([], option::some::<@expr>(e), e.id); + let blk_ = default_block([], option::some::<@expr>(e), e.id); ret {node: blk_, span: e.span}; } -fn checked_block(stmts1: [@stmt], expr1: option::t<@expr>, id1: node_id) -> +fn default_block(stmts1: [@stmt], expr1: option::t<@expr>, id1: node_id) -> blk_ { - ret {stmts: stmts1, expr: expr1, id: id1, rules: checked_blk}; + ret {stmts: stmts1, expr: expr1, id: id1, rules: default_blk}; } fn obj_field_from_anon_obj_field(f: anon_obj_field) -> obj_field { diff --git a/src/comp/syntax/parse/parser.rs b/src/comp/syntax/parse/parser.rs index 75b72acba3f0..ab573691720d 100644 --- a/src/comp/syntax/parse/parser.rs +++ b/src/comp/syntax/parse/parser.rs @@ -828,7 +828,7 @@ fn parse_bottom_expr(p: parser) -> @ast::expr { p.peek() == token::OROR { ret parse_fn_block_expr(p); } else { - let blk = parse_block_tail(p, lo, ast::checked_blk); + let blk = parse_block_tail(p, lo, ast::default_blk); ret mk_expr(p, blk.span.lo, blk.span.hi, ast::expr_block(blk)); } } else if eat_word(p, "if") { @@ -873,7 +873,7 @@ fn parse_bottom_expr(p: parser) -> @ast::expr { } else if p.peek() == token::POUND_LBRACE { p.bump(); let blk = ast::mac_embed_block( - parse_block_tail(p, lo, ast::checked_blk)); + parse_block_tail(p, lo, ast::default_blk)); ret mk_mac_expr(p, lo, p.get_hi_pos(), blk); } else if p.peek() == token::ELLIPSIS { p.bump(); @@ -1320,7 +1320,7 @@ fn parse_fn_expr(p: parser, proto: ast::proto) -> @ast::expr { fn parse_fn_block_expr(p: parser) -> @ast::expr { let lo = p.get_last_lo_pos(); let decl = parse_fn_block_decl(p); - let body = parse_block_tail(p, lo, ast::checked_blk); + let body = parse_block_tail(p, lo, ast::default_blk); let _fn = {decl: decl, proto: ast::proto_block, body: body}; ret mk_expr(p, lo, body.span.hi, ast::expr_fn(_fn)); } @@ -1684,12 +1684,14 @@ fn stmt_ends_with_semi(stmt: ast::stmt) -> bool { fn parse_block(p: parser) -> ast::blk { let lo = p.get_lo_pos(); if eat_word(p, "unchecked") { + expect(p, token::LBRACE); be parse_block_tail(p, lo, ast::unchecked_blk); } else if eat_word(p, "unsafe") { + expect(p, token::LBRACE); be parse_block_tail(p, lo, ast::unsafe_blk); } else { expect(p, token::LBRACE); - be parse_block_tail(p, lo, ast::checked_blk); + be parse_block_tail(p, lo, ast::default_blk); } } diff --git a/src/comp/syntax/print/pprust.rs b/src/comp/syntax/print/pprust.rs index 10b5db1e1290..b806df75128d 100644 --- a/src/comp/syntax/print/pprust.rs +++ b/src/comp/syntax/print/pprust.rs @@ -575,7 +575,7 @@ fn print_possibly_embedded_block(s: ps, blk: ast::blk, embedded: embed_type, alt blk.node.rules { ast::unchecked_blk. { word(s.s, "unchecked"); } ast::unsafe_blk. { word(s.s, "unsafe"); } - ast::checked_blk. { } + ast::default_blk. { } } maybe_print_comment(s, blk.span.lo); diff --git a/src/test/run-pass/unsafe-fn-called-from-unsafe-blk.rs b/src/test/run-pass/unsafe-fn-called-from-unsafe-blk.rs index 39cdd19a794a..af2b09cc37ae 100644 --- a/src/test/run-pass/unsafe-fn-called-from-unsafe-blk.rs +++ b/src/test/run-pass/unsafe-fn-called-from-unsafe-blk.rs @@ -4,8 +4,15 @@ unsafe fn f() { ret; } -fn main() { +fn g() { unsafe { f(); } } + +fn h() unsafe { + f(); +} + +fn main() { +}