Skip to content

Commit 8fc9444

Browse files
nikomatsakisbrson
authored andcommitted
---
yaml --- r: 5806 b: refs/heads/master c: 215b1ab h: refs/heads/master v: v3
1 parent 83db997 commit 8fc9444

File tree

4 files changed

+13
-29
lines changed

4 files changed

+13
-29
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: 3b668066245bf158ef2b990ac80199117b7097b5
2+
refs/heads/master: 215b1ab000465481b82a347ed02e4489f061813e

trunk/src/comp/middle/typeck.rs

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1528,7 +1528,7 @@ fn require_unsafe(sess: session::session, f_purity: ast::purity, sp: span) {
15281528
alt f_purity {
15291529
ast::unsafe_fn. { ret; }
15301530
_ {
1531-
sess.span_fatal(
1531+
sess.span_err(
15321532
sp,
15331533
"unsafe operation requires unsafe function or block");
15341534
}
@@ -1541,7 +1541,7 @@ fn require_impure(sess: session::session, f_purity: ast::purity, sp: span) {
15411541
ast::unsafe_fn. { ret; }
15421542
ast::impure_fn. { ret; }
15431543
ast::pure_fn. {
1544-
sess.span_fatal(sp, "Found impure expression in pure function decl");
1544+
sess.span_err(sp, "Found impure expression in pure function decl");
15451545
}
15461546
}
15471547
}
@@ -1556,7 +1556,7 @@ fn require_pure_call(ccx: @crate_ctxt, caller_purity: ast::purity,
15561556
some(ast::def_fn(_, ast::unsafe_fn.)) |
15571557
some(ast::def_native_fn(_, ast::unsafe_fn.)) {
15581558
if sess.get_opts().check_unsafe {
1559-
ccx.tcx.sess.span_fatal(
1559+
ccx.tcx.sess.span_err(
15601560
sp,
15611561
"safe function calls function marked unsafe");
15621562
}
@@ -1570,7 +1570,7 @@ fn require_pure_call(ccx: @crate_ctxt, caller_purity: ast::purity,
15701570
alt ccx.tcx.def_map.find(callee.id) {
15711571
some(ast::def_fn(_, ast::pure_fn.)) { ret; }
15721572
_ {
1573-
ccx.tcx.sess.span_fatal
1573+
ccx.tcx.sess.span_err
15741574
(sp, "pure function calls function not known to be pure");
15751575
}
15761576
}
@@ -1591,23 +1591,6 @@ fn check_expr_with(fcx: @fn_ctxt, expr: @ast::expr, expected: ty::t) -> bool {
15911591
ret check_expr_with_unifier(fcx, expr, demand::simple, expected);
15921592
}
15931593

1594-
fn check_for_unsafe_assignments(fcx: @fn_ctxt, lhs: @ast::expr) {
1595-
alt lhs.node {
1596-
ast::expr_unary(ast::deref., ptr) {
1597-
let ty = expr_ty(fcx.ccx.tcx, ptr);
1598-
let sty = structure_of(fcx, ptr.span, ty);
1599-
alt sty {
1600-
ty::ty_ptr(_) {
1601-
require_unsafe(fcx.ccx.tcx.sess, fcx.purity, lhs.span);
1602-
}
1603-
_ {}
1604-
}
1605-
}
1606-
_ {
1607-
}
1608-
}
1609-
}
1610-
16111594
fn check_expr_with_unifier(fcx: @fn_ctxt, expr: @ast::expr, unify: unifier,
16121595
expected: ty::t) -> bool {
16131596
//log_err "typechecking expr " + syntax::print::pprust::expr_to_str(expr);
@@ -1719,7 +1702,6 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, expr: @ast::expr, unify: unifier,
17191702
rhs: @ast::expr, id: ast::node_id) -> bool {
17201703
let t = next_ty_var(fcx);
17211704
let bot = check_expr_with(fcx, lhs, t) | check_expr_with(fcx, rhs, t);
1722-
check_for_unsafe_assignments(fcx, lhs);
17231705
write::ty_only_fixup(fcx, id, ty::mk_nil(fcx.ccx.tcx));
17241706
ret bot;
17251707
}
@@ -1872,7 +1854,10 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, expr: @ast::expr, unify: unifier,
18721854
oper_t =
18731855
ty::substitute_type_params(tcx, tps, variants[0].args[0]);
18741856
}
1875-
ty::ty_ptr(inner) { oper_t = inner.ty; }
1857+
ty::ty_ptr(inner) {
1858+
oper_t = inner.ty;
1859+
require_unsafe(fcx.ccx.tcx.sess, fcx.purity, expr.span);
1860+
}
18761861
_ {
18771862
tcx.sess.span_fatal(expr.span,
18781863
"dereferencing non-" +

trunk/src/test/compile-fail/unsafe-fn-deref-ptr.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
// -*- rust -*-
22
// error-pattern: unsafe operation requires unsafe function or block
33

4-
fn f(p: *u8) {
5-
*p = 0u8;
6-
ret;
4+
fn f(p: *u8) -> u8 {
5+
ret *p;
76
}
87

98
fn main() {

trunk/src/test/stdtest/str.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,14 +264,14 @@ fn str_from_cstr() unsafe {
264264
}
265265

266266
#[test]
267-
fn as_buf() {
267+
fn as_buf() unsafe {
268268
let a = "Abcdefg";
269269
let b = str::as_buf(a, {|buf| assert (*buf == 65u8); 100 });
270270
assert (b == 100);
271271
}
272272

273273
#[test]
274-
fn as_buf_small() {
274+
fn as_buf_small() unsafe {
275275
let a = "A";
276276
let b = str::as_buf(a, {|buf| assert (*buf == 65u8); 100 });
277277
assert (b == 100);

0 commit comments

Comments
 (0)