Skip to content

Commit c9e51cb

Browse files
nikomatsakisbrson
authored andcommitted
---
yaml --- r: 5775 b: refs/heads/master c: 58b8e88 h: refs/heads/master i: 5773: 7989f09 5771: af5274c 5767: 1963939 5759: 2ce1f95 v: v3
1 parent 176188a commit c9e51cb

File tree

5 files changed

+30
-19
lines changed

5 files changed

+30
-19
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: 9476692b525024ab81dfc7104f63c85af68d6eb6
2+
refs/heads/master: 58b8e88356187b8631f24fa787c0dfefcb6a1970

trunk/src/comp/middle/alias.rs

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ tag ret_info { by_ref(bool, node_id); other; }
2929
type scope = {bs: [binding], ret_info: ret_info};
3030

3131
fn mk_binding(cx: ctx, id: node_id, span: span, root_var: option::t<node_id>,
32-
unsafe: [unsafe_ty]) -> binding {
32+
unsafe_tys: [unsafe_ty]) -> binding {
3333
ret @{node_id: id, span: span, root_var: root_var,
3434
local_id: local_id_of_node(cx, id),
35-
unsafe_tys: unsafe, mutable ok: valid,
35+
unsafe_tys: unsafe_tys, mutable ok: valid,
3636
mutable copied: not_copied};
3737
}
3838

@@ -284,12 +284,12 @@ fn check_call(cx: ctx, f: @ast::expr, args: [@ast::expr]) -> [binding] {
284284
}
285285
let j = 0u;
286286
for b in bindings {
287-
for unsafe in b.unsafe_tys {
287+
for unsafe_ty in b.unsafe_tys {
288288
let i = 0u;
289289
for arg_t: ty::arg in arg_ts {
290290
let mut_alias = arg_t.mode == ast::by_mut_ref;
291291
if i != j &&
292-
ty_can_unsafely_include(cx, unsafe, arg_t.ty,
292+
ty_can_unsafely_include(cx, unsafe_ty, arg_t.ty,
293293
mut_alias) &&
294294
cant_copy(cx, b) {
295295
cx.tcx.sess.span_err
@@ -397,24 +397,28 @@ fn check_alt(cx: ctx, input: @ast::expr, arms: [ast::arm], sc: scope,
397397
let new_bs = sc.bs;
398398
let root_var = path_def_id(cx, root.ex);
399399
let pat_id_map = ast_util::pat_id_map(a.pats[0]);
400-
type info = {id: node_id, mutable unsafe: [unsafe_ty], span: span};
400+
type info = {
401+
id: node_id,
402+
mutable unsafe_tys: [unsafe_ty],
403+
span: span};
401404
let binding_info: [info] = [];
402405
for pat in a.pats {
403406
for proot in pattern_roots(cx.tcx, root.mut, pat) {
404407
let canon_id = pat_id_map.get(proot.name);
405408
alt vec::find({|x| x.id == canon_id}, binding_info) {
406-
some(s) { s.unsafe += unsafe_set(proot.mut); }
409+
some(s) { s.unsafe_tys += unsafe_set(proot.mut); }
407410
none. {
408-
binding_info += [{id: canon_id,
409-
mutable unsafe: unsafe_set(proot.mut),
410-
span: proot.span}];
411+
binding_info += [
412+
{id: canon_id,
413+
mutable unsafe_tys: unsafe_set(proot.mut),
414+
span: proot.span}];
411415
}
412416
}
413417
}
414418
}
415419
for info in binding_info {
416420
new_bs += [mk_binding(cx, info.id, info.span, root_var,
417-
copy info.unsafe)];
421+
copy info.unsafe_tys)];
418422
}
419423
visit::visit_arm(a, {bs: new_bs with sc}, v);
420424
}
@@ -470,8 +474,8 @@ fn check_var(cx: ctx, ex: @ast::expr, p: ast::path, id: ast::node_id,
470474
for b in sc.bs {
471475
// excludes variables introduced since the alias was made
472476
if my_local_id < b.local_id {
473-
for unsafe in b.unsafe_tys {
474-
if ty_can_unsafely_include(cx, unsafe, var_t, assign) {
477+
for unsafe_ty in b.unsafe_tys {
478+
if ty_can_unsafely_include(cx, unsafe_ty, var_t, assign) {
475479
b.ok = val_taken(ex.span, p);
476480
}
477481
}
@@ -689,9 +693,9 @@ fn pattern_roots(tcx: ty::ctxt, mut: option::t<unsafe_ty>, pat: @ast::pat)
689693
fn expr_root(cx: ctx, ex: @ast::expr, autoderef: bool)
690694
-> {ex: @ast::expr, mut: option::t<unsafe_ty>} {
691695
let base_root = mut::expr_root(cx.tcx, ex, autoderef);
692-
let unsafe = none;
696+
let unsafe_ty = none;
693697
for d in *base_root.ds {
694-
if d.mut { unsafe = some(contains(d.outer_t)); break; }
698+
if d.mut { unsafe_ty = some(contains(d.outer_t)); break; }
695699
}
696700
if is_none(path_def_id(cx, base_root.ex)) {
697701
alt base_root.ex.node {
@@ -703,18 +707,18 @@ fn expr_root(cx: ctx, ex: @ast::expr, autoderef: bool)
703707
let arg_root = expr_root(cx, arg, false);
704708
if mut {
705709
let ret_ty = ty::expr_ty(cx.tcx, base_root.ex);
706-
unsafe = some(mut_contains(ret_ty));
710+
unsafe_ty = some(mut_contains(ret_ty));
707711
}
708-
if !is_none(arg_root.mut) { unsafe = arg_root.mut; }
709-
ret {ex: arg_root.ex, mut: unsafe};
712+
if !is_none(arg_root.mut) { unsafe_ty = arg_root.mut; }
713+
ret {ex: arg_root.ex, mut: unsafe_ty};
710714
}
711715
_ {}
712716
}
713717
}
714718
_ {}
715719
}
716720
}
717-
ret {ex: base_root.ex, mut: unsafe};
721+
ret {ex: base_root.ex, mut: unsafe_ty};
718722
}
719723

720724
fn unsafe_set(from: option::t<unsafe_ty>) -> [unsafe_ty] {

trunk/src/comp/middle/typeck.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1525,6 +1525,7 @@ fn check_pat(fcx: @fn_ctxt, map: ast_util::pat_id_map, pat: @ast::pat,
15251525

15261526
fn require_impure(sess: session::session, f_purity: ast::purity, sp: span) {
15271527
alt f_purity {
1528+
ast::unsafe_fn. { ret; }
15281529
ast::impure_fn. { ret; }
15291530
ast::pure_fn. {
15301531
sess.span_fatal(sp, "Found impure expression in pure function decl");

trunk/src/comp/syntax/ast.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,7 @@ type fn_decl =
390390

391391
tag purity {
392392
pure_fn; // declared with "pure fn"
393+
unsafe_fn; // declared with "unsafe fn"
393394
impure_fn; // declared with "fn"
394395
}
395396

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ fn bad_expr_word_table() -> hashmap<str, ()> {
165165
words.insert("fn", ());
166166
words.insert("lambda", ());
167167
words.insert("pure", ());
168+
words.insert("unsafe", ());
168169
words.insert("iter", ());
169170
words.insert("block", ());
170171
words.insert("import", ());
@@ -2153,6 +2154,10 @@ fn parse_item(p: parser, attrs: [ast::attribute]) -> option::t<@ast::item> {
21532154
let proto = parse_fn_proto(p);
21542155
ret some(parse_item_fn_or_iter(p, ast::pure_fn, proto, attrs,
21552156
ast::il_normal));
2157+
} else if eat_word(p, "unsafe") {
2158+
expect_word(p, "fn");
2159+
ret some(parse_item_fn_or_iter(p, ast::unsafe_fn, ast::proto_fn,
2160+
attrs, ast::il_normal));
21562161
} else if eat_word(p, "iter") {
21572162
ret some(parse_item_fn_or_iter(p, ast::impure_fn, ast::proto_iter,
21582163
attrs, ast::il_normal));

0 commit comments

Comments
 (0)