]> git.lizzy.rs Git - rust.git/commitdiff
rustc: Remove moved_variables_set
authorFlavio Percoco <flaper87@gmail.com>
Tue, 22 Apr 2014 22:59:42 +0000 (00:59 +0200)
committerFlavio Percoco <flaper87@gmail.com>
Wed, 23 Apr 2014 16:22:05 +0000 (18:22 +0200)
15 files changed:
src/librustc/driver/driver.rs
src/librustc/middle/borrowck/mod.rs
src/librustc/middle/moves.rs
src/test/compile-fail/borrowck-preserve-box-in-field.rs [new file with mode: 0644]
src/test/compile-fail/borrowck-preserve-box-in-uniq.rs [new file with mode: 0644]
src/test/compile-fail/borrowck-preserve-box.rs [new file with mode: 0644]
src/test/compile-fail/borrowck-preserve-cond-box.rs [new file with mode: 0644]
src/test/compile-fail/borrowck-preserve-expl-deref.rs [new file with mode: 0644]
src/test/compile-fail/regions-appearance-constraint.rs [new file with mode: 0644]
src/test/run-pass/borrowck-preserve-box-in-field.rs [deleted file]
src/test/run-pass/borrowck-preserve-box-in-uniq.rs [deleted file]
src/test/run-pass/borrowck-preserve-box.rs [deleted file]
src/test/run-pass/borrowck-preserve-cond-box.rs [deleted file]
src/test/run-pass/borrowck-preserve-expl-deref.rs [deleted file]
src/test/run-pass/regions-appearance-constraint.rs [deleted file]

index ebac18086c03f628f8f52d032ee899d3e10f73b5..10650b747bd78d3deea1be8c24987224d2177ffa 100644 (file)
@@ -348,8 +348,7 @@ pub fn phase_3_run_analysis_passes(sess: Session,
     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));
 
@@ -361,11 +360,9 @@ pub fn phase_3_run_analysis_passes(sess: Session,
 
     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));
index 47aa7907b5ab0986db14dd0becede8a6a0c82f99..5504393e7c27378bd8ce57f0b6ea458fcd230dde 100644 (file)
@@ -77,13 +77,11 @@ fn visit_item(&mut self, item: &ast::Item, _: ()) {
 
 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),
@@ -168,7 +166,6 @@ fn borrowck_fn(this: &mut BorrowckCtxt,
 pub struct BorrowckCtxt<'a> {
     tcx: &'a ty::ctxt,
     moves_map: &'a NodeSet,
-    moved_variables_set: &'a NodeSet,
     capture_map: &'a moves::CaptureMap,
 
     // Statistics:
index 53d3dec671301d1e9a6a218087a1f00fce757b2c..1e44e1ab7f967b0a335d30e51872c08a135fc047 100644 (file)
@@ -101,11 +101,6 @@ struct Foo { a: int, b: ~int }
 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).
@@ -170,7 +165,6 @@ pub struct MoveMaps {
      * 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
 }
 
@@ -206,7 +200,6 @@ pub fn compute_moves(tcx: &ty::ctxt, krate: &Crate) -> MoveMaps {
         tcx: tcx,
         move_maps: MoveMaps {
             moves_map: NodeSet::new(),
-            moved_variables_set: NodeSet::new(),
             capture_map: NodeMap::new()
         }
     };
@@ -326,19 +319,6 @@ pub fn use_expr(&mut self,
         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.
@@ -475,6 +455,7 @@ fn has_dtor(tcx: &ty::ctxt, ty: ty::t) -> bool {
                 self.use_expr(base, Read);
             }
 
+            ExprPath(..) |
             ExprInlineAsm(..) |
             ExprBreak(..) |
             ExprAgain(..) |
diff --git a/src/test/compile-fail/borrowck-preserve-box-in-field.rs b/src/test/compile-fail/borrowck-preserve-box-in-field.rs
new file mode 100644 (file)
index 0000000..ff13845
--- /dev/null
@@ -0,0 +1,39 @@
+// 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);
+    })
+}
diff --git a/src/test/compile-fail/borrowck-preserve-box-in-uniq.rs b/src/test/compile-fail/borrowck-preserve-box-in-uniq.rs
new file mode 100644 (file)
index 0000000..b06eb0d
--- /dev/null
@@ -0,0 +1,39 @@
+// 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);
+    })
+}
diff --git a/src/test/compile-fail/borrowck-preserve-box.rs b/src/test/compile-fail/borrowck-preserve-box.rs
new file mode 100644 (file)
index 0000000..1a920c7
--- /dev/null
@@ -0,0 +1,37 @@
+// 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);
+    })
+}
diff --git a/src/test/compile-fail/borrowck-preserve-cond-box.rs b/src/test/compile-fail/borrowck-preserve-cond-box.rs
new file mode 100644 (file)
index 0000000..7000e23
--- /dev/null
@@ -0,0 +1,45 @@
+// 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);
+}
diff --git a/src/test/compile-fail/borrowck-preserve-expl-deref.rs b/src/test/compile-fail/borrowck-preserve-expl-deref.rs
new file mode 100644 (file)
index 0000000..aeabf6d
--- /dev/null
@@ -0,0 +1,39 @@
+// 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);
+    })
+}
diff --git a/src/test/compile-fail/regions-appearance-constraint.rs b/src/test/compile-fail/regions-appearance-constraint.rs
new file mode 100644 (file)
index 0000000..68bbebb
--- /dev/null
@@ -0,0 +1,35 @@
+// 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() {}
diff --git a/src/test/run-pass/borrowck-preserve-box-in-field.rs b/src/test/run-pass/borrowck-preserve-box-in-field.rs
deleted file mode 100644 (file)
index f05b8c6..0000000
+++ /dev/null
@@ -1,37 +0,0 @@
-// 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);
-    })
-}
diff --git a/src/test/run-pass/borrowck-preserve-box-in-uniq.rs b/src/test/run-pass/borrowck-preserve-box-in-uniq.rs
deleted file mode 100644 (file)
index 0896d4d..0000000
+++ /dev/null
@@ -1,37 +0,0 @@
-// 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);
-    })
-}
diff --git a/src/test/run-pass/borrowck-preserve-box.rs b/src/test/run-pass/borrowck-preserve-box.rs
deleted file mode 100644 (file)
index cfb9a4b..0000000
+++ /dev/null
@@ -1,35 +0,0 @@
-// 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);
-    })
-}
diff --git a/src/test/run-pass/borrowck-preserve-cond-box.rs b/src/test/run-pass/borrowck-preserve-cond-box.rs
deleted file mode 100644 (file)
index 52ea474..0000000
+++ /dev/null
@@ -1,45 +0,0 @@
-// 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);
-}
diff --git a/src/test/run-pass/borrowck-preserve-expl-deref.rs b/src/test/run-pass/borrowck-preserve-expl-deref.rs
deleted file mode 100644 (file)
index 749c806..0000000
+++ /dev/null
@@ -1,37 +0,0 @@
-// 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);
-    })
-}
diff --git a/src/test/run-pass/regions-appearance-constraint.rs b/src/test/run-pass/regions-appearance-constraint.rs
deleted file mode 100644 (file)
index a65a878..0000000
+++ /dev/null
@@ -1,36 +0,0 @@
-// 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() {
-}