Skip to content

Commit 7a14f49

Browse files
committed
Update tests for the Send - 'static change.
1 parent adfcd93 commit 7a14f49

25 files changed

+52
-183
lines changed

src/libstd/old_io/net/pipe.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ mod tests {
287287

288288
pub fn smalltest<F,G>(server: F, client: G)
289289
where F : FnOnce(UnixStream), F : Send,
290-
G : FnOnce(UnixStream), G : Send
290+
G : FnOnce(UnixStream), G : Send + 'static
291291
{
292292
let path1 = next_test_unix();
293293
let path2 = path1.clone();

src/libstd/process.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ impl Child {
458458
/// the parent waits for the child to exit.
459459
pub fn wait_with_output(mut self) -> io::Result<Output> {
460460
drop(self.stdin.take());
461-
fn read<T: Read + Send>(stream: Option<T>) -> Receiver<io::Result<Vec<u8>>> {
461+
fn read<T: Read + Send + 'static>(stream: Option<T>) -> Receiver<io::Result<Vec<u8>>> {
462462
let (tx, rx) = channel();
463463
match stream {
464464
Some(stream) => {

src/libstd/thread.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,7 @@ mod test {
630630
rx.recv().unwrap();
631631
}
632632

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

636636
let x = box 1;
@@ -677,7 +677,7 @@ mod test {
677677
// (well, it would if the constant were 8000+ - I lowered it to be more
678678
// valgrind-friendly. try this at home, instead..!)
679679
static GENERATIONS: uint = 16;
680-
fn child_no(x: uint) -> Thunk {
680+
fn child_no(x: uint) -> Thunk<'static> {
681681
return Thunk::new(move|| {
682682
if x < GENERATIONS {
683683
Thread::spawn(move|| child_no(x+1).invoke(()));

src/test/auxiliary/cci_capture_clause.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use std::thread::Thread;
1212
use std::sync::mpsc::{Receiver, channel};
1313

14-
pub fn foo<T:Send + Clone>(x: T) -> Receiver<T> {
14+
pub fn foo<T:'static + Send + Clone>(x: T) -> Receiver<T> {
1515
let (tx, rx) = channel();
1616
Thread::spawn(move|| {
1717
tx.send(x.clone());

src/test/bench/shootout-reverse-complement.rs

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -229,21 +229,12 @@ unsafe impl<T: 'static> Send for Racy<T> {}
229229

230230
/// Executes a closure in parallel over the given iterator over mutable slice.
231231
/// The closure `f` is run in parallel with an element of `iter`.
232-
fn parallel<'a, I, T, F>(iter: I, f: F)
233-
where T: 'a+Send + Sync,
234-
I: Iterator<Item=&'a mut [T]>,
235-
F: Fn(&mut [T]) + Sync {
236-
use std::mem;
237-
use std::raw::Repr;
238-
239-
iter.map(|chunk| {
240-
// Need to convert `f` and `chunk` to something that can cross the task
241-
// boundary.
242-
let f = Racy(&f as *const F as *const uint);
243-
let raw = Racy(chunk.repr());
232+
fn parallel<'a, I: Iterator, F>(iter: I, ref f: F)
233+
where I::Item: Send + 'a,
234+
F: Fn(I::Item) + Sync + 'a {
235+
iter.map(|x| {
244236
Thread::scoped(move|| {
245-
let f = f.0 as *const F;
246-
unsafe { (*f)(mem::transmute(raw.0)) }
237+
f(x)
247238
})
248239
}).collect::<Vec<_>>();
249240
}

src/test/bench/shootout-spectralnorm.rs

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -112,26 +112,16 @@ fn dot(v: &[f64], u: &[f64]) -> f64 {
112112
}
113113

114114

115-
struct Racy<T>(T);
116-
117-
unsafe impl<T: 'static> Send for Racy<T> {}
118-
119115
// Executes a closure in parallel over the given mutable slice. The closure `f`
120116
// is run in parallel and yielded the starting index within `v` as well as a
121117
// sub-slice of `v`.
122-
fn parallel<T, F>(v: &mut [T], f: F)
123-
where T: Send + Sync,
124-
F: Fn(uint, &mut [T]) + Sync {
118+
fn parallel<'a,T, F>(v: &mut [T], ref f: F)
119+
where T: Send + Sync + 'a,
120+
F: Fn(uint, &mut [T]) + Sync + 'a {
125121
let size = v.len() / os::num_cpus() + 1;
126-
127122
v.chunks_mut(size).enumerate().map(|(i, chunk)| {
128-
// Need to convert `f` and `chunk` to something that can cross the task
129-
// boundary.
130-
let f = Racy(&f as *const _ as *const uint);
131-
let raw = Racy(chunk.repr());
132123
Thread::scoped(move|| {
133-
let f = f.0 as *const F;
134-
unsafe { (*f)(i * size, mem::transmute(raw.0)) }
124+
f(i * size, chunk)
135125
})
136126
}).collect::<Vec<_>>();
137127
}

src/test/compile-fail/builtin-superkinds-simple.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
trait Foo : Send { }
1515

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

1919
fn main() { }

src/test/compile-fail/coherence-impls-builtin.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
#![feature(optin_builtin_traits)]
12+
1113
use std::marker::Send;
1214

1315
enum TestE {
@@ -16,18 +18,21 @@ enum TestE {
1618

1719
struct MyType;
1820

21+
struct NotSync;
22+
impl !Sync for NotSync {}
23+
1924
unsafe impl Send for TestE {}
2025
unsafe impl Send for MyType {}
2126
unsafe impl Send for (MyType, MyType) {}
2227
//~^ ERROR builtin traits can only be implemented on structs or enums
2328

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

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

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

3338
fn is_send<T: Send>() {}

src/test/compile-fail/kindck-impl-type-params.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ struct S<T>;
1717

1818
trait Gettable<T> {}
1919

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

2222
fn f<T>(val: T) {
2323
let t: S<T> = S;

src/test/compile-fail/kindck-send-object.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ trait Message : Send { }
2020

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

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

3030
fn object_with_send_bound_ok() {
31-
assert_send::<&'static (Dummy+Send)>();
31+
assert_send::<&'static (Dummy+Sync)>();
3232
assert_send::<Box<Dummy+Send>>();
3333
}
3434

0 commit comments

Comments
 (0)