about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2014-04-09 18:31:58 -0700
committerbors <bors@rust-lang.org>2014-04-09 18:31:58 -0700
commit7fbcb400f0697621ece9f9773b0f0bf1ec73e9c1 (patch)
treef5819541c9e616b0a979800c03b7fd8993c319de /src
parente2c84a78b4a3e95ea0def29172022ef4cf695958 (diff)
parent767ed1a71f07e869e07bde138845e16b320908ec (diff)
downloadrust-7fbcb400f0697621ece9f9773b0f0bf1ec73e9c1.tar.gz
rust-7fbcb400f0697621ece9f9773b0f0bf1ec73e9c1.zip
auto merge of #13413 : alexcrichton/rust/once-fn-move, r=brson
This fixes the categorization of the upvars of procs (represented internally
as once fns) to consider usage to require a loan. In doing so, upvars are no
longer allowed to be moved out of repeatedly in loops and such.

Closes #10398
Closes #12041
Closes #12127
Diffstat (limited to 'src')
-rw-r--r--src/librustc/middle/borrowck/mod.rs3
-rw-r--r--src/test/compile-fail/issue-10398.rs19
-rw-r--r--src/test/compile-fail/issue-11925.rs2
-rw-r--r--src/test/compile-fail/issue-12041.rs21
-rw-r--r--src/test/compile-fail/issue-12127.rs18
5 files changed, 61 insertions, 2 deletions
diff --git a/src/librustc/middle/borrowck/mod.rs b/src/librustc/middle/borrowck/mod.rs
index 6f4f2f6345e..cf558c6afe3 100644
--- a/src/librustc/middle/borrowck/mod.rs
+++ b/src/librustc/middle/borrowck/mod.rs
@@ -274,12 +274,13 @@ pub fn opt_loan_path(cmt: mc::cmt) -> Option<@LoanPath> {
     match cmt.cat {
         mc::cat_rvalue(..) |
         mc::cat_static_item |
-        mc::cat_copied_upvar(_) => {
+        mc::cat_copied_upvar(mc::CopiedUpvar { onceness: ast::Many, .. }) => {
             None
         }
 
         mc::cat_local(id) |
         mc::cat_arg(id) |
+        mc::cat_copied_upvar(mc::CopiedUpvar { upvar_id: id, .. }) |
         mc::cat_upvar(ty::UpvarId {var_id: id, ..}, _) => {
             Some(@LpVar(id))
         }
diff --git a/src/test/compile-fail/issue-10398.rs b/src/test/compile-fail/issue-10398.rs
new file mode 100644
index 00000000000..a58c88737b6
--- /dev/null
+++ b/src/test/compile-fail/issue-10398.rs
@@ -0,0 +1,19 @@
+// Copyright 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.
+
+fn main() {
+    let x = ~1;
+    let f: proc() = proc() {
+        let _a = x;
+        drop(x);
+        //~^ ERROR: use of moved value: `x`
+    };
+    f();
+}
diff --git a/src/test/compile-fail/issue-11925.rs b/src/test/compile-fail/issue-11925.rs
index 06a976ecf3d..0b8eaa5b831 100644
--- a/src/test/compile-fail/issue-11925.rs
+++ b/src/test/compile-fail/issue-11925.rs
@@ -11,7 +11,7 @@
 fn main() {
     let r = {
         let x = ~42;
-        let f = proc() &x; //~ ERROR: borrowed value does not live long enough
+        let f = proc() &x; //~ ERROR: `x` does not live long enough
         f()
     };
 
diff --git a/src/test/compile-fail/issue-12041.rs b/src/test/compile-fail/issue-12041.rs
new file mode 100644
index 00000000000..9ad59367312
--- /dev/null
+++ b/src/test/compile-fail/issue-12041.rs
@@ -0,0 +1,21 @@
+// Copyright 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.
+
+fn main() {
+    let (tx, rx) = channel();
+    spawn(proc() {
+        loop {
+            let tx = tx;
+            //~^ ERROR: use of moved value: `tx`
+            tx.send(1);
+        }
+    });
+}
+
diff --git a/src/test/compile-fail/issue-12127.rs b/src/test/compile-fail/issue-12127.rs
new file mode 100644
index 00000000000..78892425770
--- /dev/null
+++ b/src/test/compile-fail/issue-12127.rs
@@ -0,0 +1,18 @@
+// Copyright 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.
+
+fn main() {
+    let f = proc() {};
+    (proc() {
+        f();
+        f();
+        //~^ ERROR: use of moved value: `f`
+    })()
+}