about summary refs log tree commit diff
diff options
context:
space:
mode:
authorHuon Wilson <dbau.pp+github@gmail.com>2015-02-14 16:05:15 +1100
committerHuon Wilson <dbau.pp+github@gmail.com>2015-02-18 08:19:22 +1100
commit22c88323f3175340b8f837fdbb9e78fd742da024 (patch)
treecff0fe83d379d7a219f26bb30259005ba494d814
parent35ca50bd5676db31a8074a216d1aadad7d434de8 (diff)
downloadrust-22c88323f3175340b8f837fdbb9e78fd742da024.tar.gz
rust-22c88323f3175340b8f837fdbb9e78fd742da024.zip
Add tests for the removal of the 'static superbound from Send.
-rwxr-xr-xsrc/test/compile-fail/send-is-not-static-ensures-scoping.rs25
-rwxr-xr-xsrc/test/run-pass/send-is-not-static-par-for.rs47
2 files changed, 72 insertions, 0 deletions
diff --git a/src/test/compile-fail/send-is-not-static-ensures-scoping.rs b/src/test/compile-fail/send-is-not-static-ensures-scoping.rs
new file mode 100755
index 00000000000..0b74892d66c
--- /dev/null
+++ b/src/test/compile-fail/send-is-not-static-ensures-scoping.rs
@@ -0,0 +1,25 @@
+// 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.
+
+#![feature(core, std_misc)]
+use std::thread::Thread;
+
+fn main() {
+    let bad = {
+        let x = 1;
+        let y = &x;
+
+        Thread::scoped(|| { //~ ERROR cannot infer an appropriate lifetime
+            let _z = y;
+        })
+    };
+
+    bad.join().ok().unwrap();
+}
diff --git a/src/test/run-pass/send-is-not-static-par-for.rs b/src/test/run-pass/send-is-not-static-par-for.rs
new file mode 100755
index 00000000000..c6b64d97fbd
--- /dev/null
+++ b/src/test/run-pass/send-is-not-static-par-for.rs
@@ -0,0 +1,47 @@
+// Copyright 2015 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.
+
+#![feature(core, std_misc)]
+use std::thread::Thread;
+use std::sync::Mutex;
+
+fn par_for<I, F>(iter: I, f: F)
+    where I: Iterator,
+          <I as Iterator>::Item: Send,
+          F: Fn(<I as Iterator>::Item) + Sync
+{
+    let f = &f;
+    let _guards: Vec<_> = iter.map(|elem| {
+        Thread::scoped(move || {
+            f(elem)
+        })
+    }).collect();
+
+}
+
+fn sum(x: &[i32]) {
+    let sum_lengths = Mutex::new(0);
+    par_for(x.windows(4), |x| {
+        *sum_lengths.lock().unwrap() += x.len()
+    });
+
+    assert_eq!(*sum_lengths.lock().unwrap(), (x.len() - 3) * 4);
+}
+
+fn main() {
+    let mut elements = [0; 20];
+
+    // iterators over references into this stack frame
+    par_for(elements.iter_mut().enumerate(), |(i, x)| {
+        *x = i as i32
+    });
+
+    sum(&elements)
+}