time(time_passes, "effect checking", (), |_|
middle::effect::check_crate(&ty_cx, krate));
- let middle::moves::MoveMaps {moves_map, moved_variables_set,
- capture_map} =
+ let middle::moves::MoveMaps {moves_map, capture_map} =
time(time_passes, "compute moves", (), |_|
middle::moves::compute_moves(&ty_cx, krate));
time(time_passes, "borrow checking", (), |_|
middle::borrowck::check_crate(&ty_cx, &moves_map,
- &moved_variables_set,
&capture_map, krate));
drop(moves_map);
- drop(moved_variables_set);
time(time_passes, "kind checking", (), |_|
kind::check_crate(&ty_cx, krate));
pub fn check_crate(tcx: &ty::ctxt,
moves_map: &NodeSet,
- moved_variables_set: &NodeSet,
capture_map: &moves::CaptureMap,
krate: &ast::Crate) {
let mut bccx = BorrowckCtxt {
tcx: tcx,
moves_map: moves_map,
- moved_variables_set: moved_variables_set,
capture_map: capture_map,
stats: @BorrowStats {
loaned_paths_same: Cell::new(0),
pub struct BorrowckCtxt<'a> {
tcx: &'a ty::ctxt,
moves_map: &'a NodeSet,
- moved_variables_set: &'a NodeSet,
capture_map: &'a moves::CaptureMap,
// Statistics:
expressions that are moved. It is more efficient therefore just to
store those entries.
-Sometimes though we want to know the variables that are moved (in
-particular in the borrow checker). For these cases, the set
-`moved_variables_set` just collects the ids of variables that are
-moved.
-
Finally, the `capture_map` maps from the node_id of a closure
expression to an array of `CaptureVar` structs detailing which
variables are captured and how (by ref, by copy, by move).
* pub Note: The `moves_map` stores expression ids that are moves,
* whereas this set stores the ids of the variables that are
* moved at some point */
- pub moved_variables_set: NodeSet,
pub capture_map: CaptureMap
}
tcx: tcx,
move_maps: MoveMaps {
moves_map: NodeSet::new(),
- moved_variables_set: NodeSet::new(),
capture_map: NodeMap::new()
}
};
debug!("comp_mode = {:?}", comp_mode);
match expr.node {
- ExprPath(..) => {
- match comp_mode {
- Move => {
- let def = self.tcx.def_map.borrow().get_copy(&expr.id);
- let r = moved_variable_node_id_from_def(def);
- for &id in r.iter() {
- self.move_maps.moved_variables_set.insert(id);
- }
- }
- Read => {}
- }
- }
-
ExprUnary(UnDeref, base) => { // *base
if !self.use_overloaded_operator(expr, base, []) {
// Moving out of *base moves out of base.
self.use_expr(base, Read);
}
+ ExprPath(..) |
ExprInlineAsm(..) |
ExprBreak(..) |
ExprAgain(..) |
--- /dev/null
+// ignore-pretty
+
+// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// exec-env:RUST_POISON_ON_FREE=1
+
+#![feature(managed_boxes)]
+
+fn borrow(x: &int, f: |x: &int|) {
+ let before = *x;
+ f(x);
+ let after = *x;
+ assert_eq!(before, after);
+}
+
+struct F { f: ~int }
+
+pub fn main() {
+ let mut x = @F {f: ~3};
+ borrow(x.f, |b_x| {
+ //~^ ERROR cannot borrow `x` as mutable because `*x.f` is also borrowed as immutable
+ assert_eq!(*b_x, 3);
+ assert_eq!(&(*x.f) as *int, &(*b_x) as *int);
+ //~^ NOTE borrow occurs due to use of `x` in closure
+ x = @F {f: ~4};
+
+ println!("&*b_x = {:p}", &(*b_x));
+ assert_eq!(*b_x, 3);
+ assert!(&(*x.f) as *int != &(*b_x) as *int);
+ })
+}
--- /dev/null
+// ignore-pretty
+
+// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// exec-env:RUST_POISON_ON_FREE=1
+
+#![feature(managed_boxes)]
+
+fn borrow(x: &int, f: |x: &int|) {
+ let before = *x;
+ f(x);
+ let after = *x;
+ assert_eq!(before, after);
+}
+
+struct F { f: ~int }
+
+pub fn main() {
+ let mut x = ~@F{f: ~3};
+ borrow(x.f, |b_x| {
+ //~^ ERROR cannot borrow `x` as mutable because `*x.f` is also borrowed as immutable
+ assert_eq!(*b_x, 3);
+ assert_eq!(&(*x.f) as *int, &(*b_x) as *int);
+ //~^ NOTE borrow occurs due to use of `x` in closure
+ *x = @F{f: ~4};
+
+ println!("&*b_x = {:p}", &(*b_x));
+ assert_eq!(*b_x, 3);
+ assert!(&(*x.f) as *int != &(*b_x) as *int);
+ })
+}
--- /dev/null
+// ignore-pretty
+
+// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// exec-env:RUST_POISON_ON_FREE=1
+
+#![feature(managed_boxes)]
+
+fn borrow(x: &int, f: |x: &int|) {
+ let before = *x;
+ f(x);
+ let after = *x;
+ assert_eq!(before, after);
+}
+
+pub fn main() {
+ let mut x = @3;
+ borrow(x, |b_x| {
+ //~^ ERROR cannot borrow `x` as mutable because `*x` is also borrowed as immutable
+ assert_eq!(*b_x, 3);
+ assert_eq!(&(*x) as *int, &(*b_x) as *int);
+ //~^ NOTE borrow occurs due to use of `x` in closure
+ x = @22;
+
+ println!("&*b_x = {:p}", &(*b_x));
+ assert_eq!(*b_x, 3);
+ assert!(&(*x) as *int != &(*b_x) as *int);
+ })
+}
--- /dev/null
+// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// exec-env:RUST_POISON_ON_FREE=1
+
+#![feature(managed_boxes)]
+
+fn testfn(cond: bool) {
+ let mut x = @3;
+ let mut y = @4;
+
+ // borrow x and y
+ let r_x = &*x;
+ let r_y = &*y;
+ let mut r = r_x;
+ let mut exp = 3;
+
+ if cond {
+ r = r_y;
+ exp = 4;
+ }
+
+ println!("*r = {}, exp = {}", *r, exp);
+ assert_eq!(*r, exp);
+
+ x = @5; //~ERROR cannot assign to `x` because it is borrowed
+ y = @6; //~ERROR cannot assign to `y` because it is borrowed
+
+ println!("*r = {}, exp = {}", *r, exp);
+ assert_eq!(*r, exp);
+ assert_eq!(x, @5);
+ assert_eq!(y, @6);
+}
+
+pub fn main() {
+ testfn(true);
+ testfn(false);
+}
--- /dev/null
+// ignore-pretty
+
+// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// exec-env:RUST_POISON_ON_FREE=1
+
+#![feature(managed_boxes)]
+
+fn borrow(x: &int, f: |x: &int|) {
+ let before = *x;
+ f(x);
+ let after = *x;
+ assert_eq!(before, after);
+}
+
+struct F { f: ~int }
+
+pub fn main() {
+ let mut x = @F {f: ~3};
+ borrow((*x).f, |b_x| {
+ //~^ ERROR cannot borrow `x` as mutable because `*x.f` is also borrowed as immutable
+ assert_eq!(*b_x, 3);
+ assert_eq!(&(*x.f) as *int, &(*b_x) as *int);
+ //~^ NOTE borrow occurs due to use of `x` in closure
+ x = @F {f: ~4};
+
+ println!("&*b_x = {:p}", &(*b_x));
+ assert_eq!(*b_x, 3);
+ assert!(&(*x.f) as *int != &(*b_x) as *int);
+ })
+}
--- /dev/null
+// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// Test no-special rooting is used for managed boxes
+
+#![feature(managed_boxes)]
+
+fn testfn(cond: bool) {
+ let mut x = @3;
+ let mut y = @4;
+
+ let mut a = &*x;
+
+ let mut exp = 3;
+ if cond {
+ a = &*y;
+
+ exp = 4;
+ }
+
+ x = @5; //~ERROR cannot assign to `x` because it is borrowed
+ y = @6; //~ERROR cannot assign to `y` because it is borrowed
+ assert_eq!(*a, exp);
+ assert_eq!(x, @5);
+ assert_eq!(y, @6);
+}
+
+pub fn main() {}
+++ /dev/null
-// ignore-pretty
-
-// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-// exec-env:RUST_POISON_ON_FREE=1
-
-#![feature(managed_boxes)]
-
-fn borrow(x: &int, f: |x: &int|) {
- let before = *x;
- f(x);
- let after = *x;
- assert_eq!(before, after);
-}
-
-struct F { f: ~int }
-
-pub fn main() {
- let mut x = @F {f: ~3};
- borrow(x.f, |b_x| {
- assert_eq!(*b_x, 3);
- assert_eq!(&(*x.f) as *int, &(*b_x) as *int);
- x = @F {f: ~4};
-
- println!("&*b_x = {:p}", &(*b_x));
- assert_eq!(*b_x, 3);
- assert!(&(*x.f) as *int != &(*b_x) as *int);
- })
-}
+++ /dev/null
-// ignore-pretty
-
-// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-// exec-env:RUST_POISON_ON_FREE=1
-
-#![feature(managed_boxes)]
-
-fn borrow(x: &int, f: |x: &int|) {
- let before = *x;
- f(x);
- let after = *x;
- assert_eq!(before, after);
-}
-
-struct F { f: ~int }
-
-pub fn main() {
- let mut x = ~@F{f: ~3};
- borrow(x.f, |b_x| {
- assert_eq!(*b_x, 3);
- assert_eq!(&(*x.f) as *int, &(*b_x) as *int);
- *x = @F{f: ~4};
-
- println!("&*b_x = {:p}", &(*b_x));
- assert_eq!(*b_x, 3);
- assert!(&(*x.f) as *int != &(*b_x) as *int);
- })
-}
+++ /dev/null
-// ignore-pretty
-
-// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-// exec-env:RUST_POISON_ON_FREE=1
-
-#![feature(managed_boxes)]
-
-fn borrow(x: &int, f: |x: &int|) {
- let before = *x;
- f(x);
- let after = *x;
- assert_eq!(before, after);
-}
-
-pub fn main() {
- let mut x = @3;
- borrow(x, |b_x| {
- assert_eq!(*b_x, 3);
- assert_eq!(&(*x) as *int, &(*b_x) as *int);
- x = @22;
-
- println!("&*b_x = {:p}", &(*b_x));
- assert_eq!(*b_x, 3);
- assert!(&(*x) as *int != &(*b_x) as *int);
- })
-}
+++ /dev/null
-// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-// exec-env:RUST_POISON_ON_FREE=1
-
-#![feature(managed_boxes)]
-
-fn testfn(cond: bool) {
- let mut x = @3;
- let mut y = @4;
-
- // borrow x and y
- let r_x = &*x;
- let r_y = &*y;
- let mut r = r_x;
- let mut exp = 3;
-
- if cond {
- r = r_y;
- exp = 4;
- }
-
- println!("*r = {}, exp = {}", *r, exp);
- assert_eq!(*r, exp);
-
- x = @5;
- y = @6;
-
- println!("*r = {}, exp = {}", *r, exp);
- assert_eq!(*r, exp);
- assert_eq!(x, @5);
- assert_eq!(y, @6);
-}
-
-pub fn main() {
- testfn(true);
- testfn(false);
-}
+++ /dev/null
-// ignore-pretty
-
-// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-// exec-env:RUST_POISON_ON_FREE=1
-
-#![feature(managed_boxes)]
-
-fn borrow(x: &int, f: |x: &int|) {
- let before = *x;
- f(x);
- let after = *x;
- assert_eq!(before, after);
-}
-
-struct F { f: ~int }
-
-pub fn main() {
- let mut x = @F {f: ~3};
- borrow((*x).f, |b_x| {
- assert_eq!(*b_x, 3);
- assert_eq!(&(*x.f) as *int, &(*b_x) as *int);
- x = @F {f: ~4};
-
- println!("&*b_x = {:p}", &(*b_x));
- assert_eq!(*b_x, 3);
- assert!(&(*x.f) as *int != &(*b_x) as *int);
- })
-}
+++ /dev/null
-// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-/* Tests conditional rooting of the box y */
-
-#![feature(managed_boxes)]
-
-fn testfn(cond: bool) {
- let mut x = @3;
- let mut y = @4;
-
- let mut a = &*x;
-
- let mut exp = 3;
- if cond {
- a = &*y;
-
- exp = 4;
- }
-
- x = @5;
- y = @6;
- assert_eq!(*a, exp);
- assert_eq!(x, @5);
- assert_eq!(y, @6);
-}
-
-pub fn main() {
-}