Skip to content

Commit

Permalink
Update tests for the Send - 'static change.
Browse files Browse the repository at this point in the history
  • Loading branch information
huonw committed Feb 18, 2015
1 parent adfcd93 commit 7a14f49
Show file tree
Hide file tree
Showing 25 changed files with 52 additions and 183 deletions.
2 changes: 1 addition & 1 deletion src/libstd/old_io/net/pipe.rs
Expand Up @@ -287,7 +287,7 @@ mod tests {

pub fn smalltest<F,G>(server: F, client: G)
where F : FnOnce(UnixStream), F : Send,
G : FnOnce(UnixStream), G : Send
G : FnOnce(UnixStream), G : Send + 'static
{
let path1 = next_test_unix();
let path2 = path1.clone();
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/process.rs
Expand Up @@ -458,7 +458,7 @@ impl Child {
/// the parent waits for the child to exit.
pub fn wait_with_output(mut self) -> io::Result<Output> {
drop(self.stdin.take());
fn read<T: Read + Send>(stream: Option<T>) -> Receiver<io::Result<Vec<u8>>> {
fn read<T: Read + Send + 'static>(stream: Option<T>) -> Receiver<io::Result<Vec<u8>>> {
let (tx, rx) = channel();
match stream {
Some(stream) => {
Expand Down
4 changes: 2 additions & 2 deletions src/libstd/thread.rs
Expand Up @@ -630,7 +630,7 @@ mod test {
rx.recv().unwrap();
}

fn avoid_copying_the_body<F>(spawnfn: F) where F: FnOnce(Thunk) {
fn avoid_copying_the_body<F>(spawnfn: F) where F: FnOnce(Thunk<'static>) {
let (tx, rx) = channel::<uint>();

let x = box 1;
Expand Down Expand Up @@ -677,7 +677,7 @@ mod test {
// (well, it would if the constant were 8000+ - I lowered it to be more
// valgrind-friendly. try this at home, instead..!)
static GENERATIONS: uint = 16;
fn child_no(x: uint) -> Thunk {
fn child_no(x: uint) -> Thunk<'static> {
return Thunk::new(move|| {
if x < GENERATIONS {
Thread::spawn(move|| child_no(x+1).invoke(()));
Expand Down
2 changes: 1 addition & 1 deletion src/test/auxiliary/cci_capture_clause.rs
Expand Up @@ -11,7 +11,7 @@
use std::thread::Thread;
use std::sync::mpsc::{Receiver, channel};

pub fn foo<T:Send + Clone>(x: T) -> Receiver<T> {
pub fn foo<T:'static + Send + Clone>(x: T) -> Receiver<T> {
let (tx, rx) = channel();
Thread::spawn(move|| {
tx.send(x.clone());
Expand Down
19 changes: 5 additions & 14 deletions src/test/bench/shootout-reverse-complement.rs
Expand Up @@ -229,21 +229,12 @@ unsafe impl<T: 'static> Send for Racy<T> {}

/// Executes a closure in parallel over the given iterator over mutable slice.
/// The closure `f` is run in parallel with an element of `iter`.
fn parallel<'a, I, T, F>(iter: I, f: F)
where T: 'a+Send + Sync,
I: Iterator<Item=&'a mut [T]>,
F: Fn(&mut [T]) + Sync {
use std::mem;
use std::raw::Repr;

iter.map(|chunk| {
// Need to convert `f` and `chunk` to something that can cross the task
// boundary.
let f = Racy(&f as *const F as *const uint);
let raw = Racy(chunk.repr());
fn parallel<'a, I: Iterator, F>(iter: I, ref f: F)
where I::Item: Send + 'a,
F: Fn(I::Item) + Sync + 'a {
iter.map(|x| {
Thread::scoped(move|| {
let f = f.0 as *const F;
unsafe { (*f)(mem::transmute(raw.0)) }
f(x)
})
}).collect::<Vec<_>>();
}
Expand Down
18 changes: 4 additions & 14 deletions src/test/bench/shootout-spectralnorm.rs
Expand Up @@ -112,26 +112,16 @@ fn dot(v: &[f64], u: &[f64]) -> f64 {
}


struct Racy<T>(T);

unsafe impl<T: 'static> Send for Racy<T> {}

// Executes a closure in parallel over the given mutable slice. The closure `f`
// is run in parallel and yielded the starting index within `v` as well as a
// sub-slice of `v`.
fn parallel<T, F>(v: &mut [T], f: F)
where T: Send + Sync,
F: Fn(uint, &mut [T]) + Sync {
fn parallel<'a,T, F>(v: &mut [T], ref f: F)
where T: Send + Sync + 'a,
F: Fn(uint, &mut [T]) + Sync + 'a {
let size = v.len() / os::num_cpus() + 1;

v.chunks_mut(size).enumerate().map(|(i, chunk)| {
// Need to convert `f` and `chunk` to something that can cross the task
// boundary.
let f = Racy(&f as *const _ as *const uint);
let raw = Racy(chunk.repr());
Thread::scoped(move|| {
let f = f.0 as *const F;
unsafe { (*f)(i * size, mem::transmute(raw.0)) }
f(i * size, chunk)
})
}).collect::<Vec<_>>();
}
4 changes: 2 additions & 2 deletions src/test/compile-fail/builtin-superkinds-simple.rs
Expand Up @@ -13,7 +13,7 @@

trait Foo : Send { }

impl <'a> Foo for &'a mut () { }
//~^ ERROR the type `&'a mut ()` does not fulfill the required lifetime
impl Foo for std::rc::Rc<i8> { }
//~^ ERROR the trait `core::marker::Send` is not implemented

fn main() { }
9 changes: 7 additions & 2 deletions src/test/compile-fail/coherence-impls-builtin.rs
Expand Up @@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![feature(optin_builtin_traits)]

use std::marker::Send;

enum TestE {
Expand All @@ -16,18 +18,21 @@ enum TestE {

struct MyType;

struct NotSync;
impl !Sync for NotSync {}

unsafe impl Send for TestE {}
unsafe impl Send for MyType {}
unsafe impl Send for (MyType, MyType) {}
//~^ ERROR builtin traits can only be implemented on structs or enums

unsafe impl Send for &'static MyType {}
unsafe impl Send for &'static NotSync {}
//~^ ERROR builtin traits can only be implemented on structs or enums

unsafe impl Send for [MyType] {}
//~^ ERROR builtin traits can only be implemented on structs or enums

unsafe impl Send for &'static [MyType] {}
unsafe impl Send for &'static [NotSync] {}
//~^ ERROR builtin traits can only be implemented on structs or enums

fn is_send<T: Send>() {}
Expand Down
2 changes: 1 addition & 1 deletion src/test/compile-fail/kindck-impl-type-params.rs
Expand Up @@ -17,7 +17,7 @@ struct S<T>;

trait Gettable<T> {}

impl<T: Send + Copy> Gettable<T> for S<T> {}
impl<T: Send + Copy + 'static> Gettable<T> for S<T> {}

fn f<T>(val: T) {
let t: S<T> = S;
Expand Down
4 changes: 2 additions & 2 deletions src/test/compile-fail/kindck-send-object.rs
Expand Up @@ -20,15 +20,15 @@ trait Message : Send { }

fn object_ref_with_static_bound_not_ok() {
assert_send::<&'static (Dummy+'static)>();
//~^ ERROR the trait `core::marker::Send` is not implemented
//~^ ERROR the trait `core::marker::Sync` is not implemented
}

fn box_object_with_no_bound_not_ok<'a>() {
assert_send::<Box<Dummy>>(); //~ ERROR the trait `core::marker::Send` is not implemented
}

fn object_with_send_bound_ok() {
assert_send::<&'static (Dummy+Send)>();
assert_send::<&'static (Dummy+Sync)>();
assert_send::<Box<Dummy+Send>>();
}

Expand Down
8 changes: 4 additions & 4 deletions src/test/compile-fail/kindck-send-object1.rs
Expand Up @@ -12,22 +12,22 @@
// is broken into two parts because some errors occur in distinct
// phases in the compiler. See kindck-send-object2.rs as well!

fn assert_send<T:Send>() { }
fn assert_send<T:Send+'static>() { }
trait Dummy { }

// careful with object types, who knows what they close over...
fn test51<'a>() {
assert_send::<&'a Dummy>();
//~^ ERROR the trait `core::marker::Send` is not implemented
//~^ ERROR the trait `core::marker::Sync` is not implemented
}
fn test52<'a>() {
assert_send::<&'a (Dummy+Send)>();
assert_send::<&'a (Dummy+Sync)>();
//~^ ERROR does not fulfill the required lifetime
}

// ...unless they are properly bounded
fn test60() {
assert_send::<&'static (Dummy+Send)>();
assert_send::<&'static (Dummy+Sync)>();
}
fn test61() {
assert_send::<Box<Dummy+Send>>();
Expand Down
4 changes: 2 additions & 2 deletions src/test/compile-fail/kindck-send-object2.rs
Expand Up @@ -14,7 +14,7 @@ fn assert_send<T:Send>() { }
trait Dummy { }

fn test50() {
assert_send::<&'static Dummy>(); //~ ERROR the trait `core::marker::Send` is not implemented
assert_send::<&'static Dummy>(); //~ ERROR the trait `core::marker::Sync` is not implemented
}

fn test53() {
Expand All @@ -23,7 +23,7 @@ fn test53() {

// ...unless they are properly bounded
fn test60() {
assert_send::<&'static (Dummy+Send)>();
assert_send::<&'static (Dummy+Sync)>();
}
fn test61() {
assert_send::<Box<Dummy+Send>>();
Expand Down
4 changes: 2 additions & 2 deletions src/test/compile-fail/kindck-send-owned.rs
Expand Up @@ -18,8 +18,8 @@ fn test31() { assert_send::<String>(); }
fn test32() { assert_send::<Vec<isize> >(); }

// but not if they own a bad thing
fn test40<'a>(_: &'a isize) {
assert_send::<Box<&'a isize>>(); //~ ERROR does not fulfill the required lifetime
fn test40() {
assert_send::<Box<*mut u8>>(); //~ ERROR `core::marker::Send` is not implemented
}

fn main() { }
34 changes: 0 additions & 34 deletions src/test/compile-fail/kindck-send-region-pointers.rs

This file was deleted.

83 changes: 0 additions & 83 deletions src/test/compile-fail/regions-bounded-by-send.rs

This file was deleted.

4 changes: 2 additions & 2 deletions src/test/compile-fail/regions-pattern-typing-issue-19552.rs
Expand Up @@ -8,11 +8,11 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

fn assert_send<T: Send>(_t: T) {}
fn assert_static<T: 'static>(_t: T) {}

fn main() {
let line = String::new();
match [&*line] { //~ ERROR `line` does not live long enough
[ word ] => { assert_send(word); }
[ word ] => { assert_static(word); }
}
}
2 changes: 1 addition & 1 deletion src/test/compile-fail/trait-bounds-cant-coerce.rs
Expand Up @@ -22,7 +22,7 @@ fn c(x: Box<Foo+Sync+Send>) {
fn d(x: Box<Foo>) {
a(x); //~ ERROR mismatched types
//~| expected `Box<Foo + Send>`
//~| found `Box<Foo + 'static>`
//~| found `Box<Foo>`
//~| expected bounds `Send`
//~| found no bounds
}
Expand Down
Expand Up @@ -22,7 +22,7 @@ trait Foo : Bar { }
impl <T: Send> Foo for T { }
impl <T: Send> Bar for T { }

fn foo<T: Foo>(val: T, chan: Sender<T>) {
fn foo<T: Foo + 'static>(val: T, chan: Sender<T>) {
chan.send(val).unwrap();
}

Expand Down
2 changes: 1 addition & 1 deletion src/test/run-pass/builtin-superkinds-capabilities-xc.rs
Expand Up @@ -25,7 +25,7 @@ struct X<T>(T);
impl <T: Sync> RequiresShare for X<T> { }
impl <T: Sync+Send> RequiresRequiresShareAndSend for X<T> { }

fn foo<T: RequiresRequiresShareAndSend>(val: T, chan: Sender<T>) {
fn foo<T: RequiresRequiresShareAndSend + 'static>(val: T, chan: Sender<T>) {
chan.send(val).unwrap();
}

Expand Down
2 changes: 1 addition & 1 deletion src/test/run-pass/builtin-superkinds-capabilities.rs
Expand Up @@ -18,7 +18,7 @@ trait Foo : Send { }

impl <T: Send> Foo for T { }

fn foo<T: Foo>(val: T, chan: Sender<T>) {
fn foo<T: Foo + 'static>(val: T, chan: Sender<T>) {
chan.send(val).unwrap();
}

Expand Down

0 comments on commit 7a14f49

Please sign in to comment.