Skip to content

Commit 0f5a4d0

Browse files
committed
---
yaml --- r: 4180 b: refs/heads/master c: f379c97 h: refs/heads/master v: v3
1 parent 2596a2c commit 0f5a4d0

File tree

5 files changed

+45
-23
lines changed

5 files changed

+45
-23
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: 06e1d8b745bf73887390ed21ca58ae5688cbe208
2+
refs/heads/master: f379c97913df637e1203d0fe2b3598b7ac9d1a17

trunk/src/comp/middle/alias.rs

Lines changed: 39 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,12 @@ type ctx = {tcx: ty::ctxt, local_map: std::map::hashmap[node_id, local_info]};
4141
fn check_crate(tcx: ty::ctxt, crate: &@ast::crate) {
4242
// Stores information about object fields and function
4343
// arguments that's otherwise not easily available.
44-
let cx =
45-
@{tcx: tcx, local_map: std::map::new_int_hash()};
46-
let v =
47-
@{visit_fn: bind visit_fn(cx, _, _, _, _, _, _, _),
48-
visit_item: bind visit_item(cx, _, _, _),
49-
visit_expr: bind visit_expr(cx, _, _, _),
50-
visit_decl: bind visit_decl(cx, _, _, _)
51-
with *visit::default_visitor[scope]()};
44+
let cx = @{tcx: tcx, local_map: std::map::new_int_hash()};
45+
let v = @{visit_fn: bind visit_fn(cx, _, _, _, _, _, _, _),
46+
visit_item: bind visit_item(cx, _, _, _),
47+
visit_expr: bind visit_expr(cx, _, _, _),
48+
visit_decl: bind visit_decl(cx, _, _, _)
49+
with *visit::default_visitor[scope]()};
5250
visit::visit_crate(*crate, @~[], visit::mk_vt(v));
5351
tcx.sess.abort_if_errors();
5452
}
@@ -158,12 +156,29 @@ fn check_call(cx: &ctx, f: &@ast::expr, args: &(@ast::expr)[], sc: &scope) ->
158156
let arg = args.(i);
159157
let root = expr_root(cx, arg, false);
160158
if arg_t.mode == ty::mo_alias(true) {
161-
alt path_def_id(cx, arg) {
162-
some(did) { mut_roots += ~[{arg: i, node: did.node}]; }
159+
alt path_def(cx, arg) {
160+
some(def) {
161+
let dnum = ast::def_id_of_def(def).node;
162+
if def_is_local(def, true) {
163+
if is_immutable_alias(cx, sc, dnum) {
164+
cx.tcx.sess.span_err
165+
(arg.span, "passing an immutable alias \
166+
by mutable alias");
167+
} else if is_immutable_objfield(cx, dnum) {
168+
cx.tcx.sess.span_err
169+
(arg.span, "passing an immutable object \
170+
field by mutable alias");
171+
}
172+
} else {
173+
cx.tcx.sess.span_err
174+
(arg.span,
175+
"passing a static item by mutable alias");
176+
}
177+
mut_roots += ~[{arg: i, node: dnum}];
178+
}
163179
_ {
164180
if !mut_field(root.ds) {
165-
let m =
166-
"passing a temporary value or \
181+
let m = "passing a temporary value or \
167182
immutable field by mutable alias";
168183
cx.tcx.sess.span_err(arg.span, m);
169184
}
@@ -391,13 +406,13 @@ fn check_lval(cx: &@ctx, dest: &@ast::expr, sc: &scope, v: &vt[scope]) {
391406
alt dest.node {
392407
ast::expr_path(p) {
393408
let dnum = ast::def_id_of_def(cx.tcx.def_map.get(dest.id)).node;
394-
if is_immutable_alias(cx, sc, dnum) {
409+
if is_immutable_alias(*cx, sc, dnum) {
395410
cx.tcx.sess.span_err(dest.span, "assigning to immutable alias");
396-
} else if (is_immutable_objfield(cx, dnum)) {
411+
} else if (is_immutable_objfield(*cx, dnum)) {
397412
cx.tcx.sess.span_err(dest.span,
398413
"assigning to immutable obj field");
399414
}
400-
for r: restrict in *sc {
415+
for r: restrict in *sc {
401416
if ivec::member(dnum, r.root_vars) {
402417
r.ok = overwritten(dest.span, p);
403418
}
@@ -452,7 +467,7 @@ fn check_assign(cx: &@ctx, dest: &@ast::expr, src: &@ast::expr, sc: &scope,
452467
}
453468

454469

455-
fn is_immutable_alias(cx: &@ctx, sc: &scope, dnum: node_id) -> bool {
470+
fn is_immutable_alias(cx: &ctx, sc: &scope, dnum: node_id) -> bool {
456471
alt cx.local_map.find(dnum) {
457472
some(arg(ast::alias(false))) { ret true; }
458473
_ { }
@@ -463,7 +478,7 @@ fn is_immutable_alias(cx: &@ctx, sc: &scope, dnum: node_id) -> bool {
463478
ret false;
464479
}
465480

466-
fn is_immutable_objfield(cx: &@ctx, dnum: node_id) -> bool {
481+
fn is_immutable_objfield(cx: &ctx, dnum: node_id) -> bool {
467482
ret cx.local_map.find(dnum) == some(objfield(ast::imm));
468483
}
469484

@@ -614,6 +629,13 @@ fn inner_mut(ds: &@deref[]) -> option::t[ty::t] {
614629
ret none;
615630
}
616631

632+
fn path_def(cx: &ctx, ex: &@ast::expr) -> option::t[ast::def] {
633+
ret alt ex.node {
634+
ast::expr_path(_) { some(cx.tcx.def_map.get(ex.id)) }
635+
_ { none }
636+
}
637+
}
638+
617639
fn path_def_id(cx: &ctx, ex: &@ast::expr) -> option::t[ast::def_id] {
618640
alt ex.node {
619641
ast::expr_path(_) {

trunk/src/lib/ptr.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// Unsafe pointer utility functions.
22

33
native "rust-intrinsic" mod rusti {
4-
fn addr_of[T](val: &mutable T) -> *mutable T;
4+
fn addr_of[T](val: &T) -> *mutable T;
55
fn ptr_offset[T](ptr: *T, count: uint) -> *T;
66
}
77

8-
fn addr_of[T](val: &mutable T) -> *mutable T { ret rusti::addr_of(val); }
8+
fn addr_of[T](val: &T) -> *mutable T { ret rusti::addr_of(val); }
99
fn offset[T](ptr: *T, count: uint) -> *T {
1010
ret rusti::ptr_offset(ptr, count);
1111
}

trunk/src/lib/test.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ tag test_result { tr_ok; tr_failed; tr_ignored; }
8888
// In cases where test functions and closures it is not ok to just dump them
8989
// into a task and run them, so this transformation gives the caller a chance
9090
// to create the test task.
91-
type test_to_task = fn(&fn() ) -> task ;
91+
type test_to_task = fn(&fn()) -> task ;
9292

9393
// A simple console test runner
9494
fn run_tests_console(opts: &test_opts, tests: &test_desc[]) -> bool {
@@ -298,7 +298,7 @@ native "rust" mod rustrt {
298298
// But, at least currently, functions can't be used as spawn arguments so
299299
// we've got to treat our test functions as unsafe pointers. This function
300300
// only works with functions that don't contain closures.
301-
fn default_test_to_task(f: &fn() ) -> task {
301+
fn default_test_to_task(f: &fn()) -> task {
302302
fn run_task(fptr: *mutable fn() ) {
303303
// If this task fails we don't want that failure to propagate to the
304304
// test runner or else we couldn't keep running tests

trunk/src/lib/vec.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ fn grow_init_fn[T](v: &mutable array[T], n: uint, init_fn: fn() -> T ) {
190190
while i > 0u { i -= 1u; v += [init_fn()]; }
191191
}
192192

193-
fn grow_init_fn_set[T](v: &array[T], index: uint, init_fn: fn() -> T ,
193+
fn grow_init_fn_set[T](v: &mutable array[T], index: uint, init_fn: fn() -> T,
194194
val: &T) {
195195
let length = vec::len(v);
196196
if index >= length { grow_init_fn(v, index - length + 1u, init_fn); }

0 commit comments

Comments
 (0)