rollup merge of #22319: huonw/send-is-not-static

Conflicts:
	src/libstd/sync/task_pool.rs
	src/libstd/thread.rs
	src/libtest/lib.rs
	src/test/bench/shootout-reverse-complement.rs
	src/test/bench/shootout-spectralnorm.rs
This commit is contained in:
Alex Crichton 2015-02-17 17:32:16 -08:00
commit ba8ce4c2c2
49 changed files with 231 additions and 297 deletions

View file

@ -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() { }

View file

@ -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 {
@ -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>() {}

View file

@ -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;

View file

@ -20,7 +20,7 @@ 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>() {
@ -28,7 +28,7 @@ fn box_object_with_no_bound_not_ok<'a>() {
}
fn object_with_send_bound_ok() {
assert_send::<&'static (Dummy+Send)>();
assert_send::<&'static (Dummy+Sync)>();
assert_send::<Box<Dummy+Send>>();
}

View file

@ -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>>();

View file

@ -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() {
@ -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>>();

View file

@ -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() { }

View file

@ -1,34 +0,0 @@
// 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.
// Test that borrowed pointers are not sendable unless 'static.
fn assert_send<T:Send>() { }
// lifetime pointers with 'static lifetime are ok
fn test01() { assert_send::<&'static isize>(); }
fn test02() { assert_send::<&'static str>(); }
fn test03() { assert_send::<&'static [isize]>(); }
// whether or not they are mutable
fn test10() { assert_send::<&'static mut isize>(); }
// otherwise lifetime pointers are not ok
fn test20<'a>(_: &'a isize) {
assert_send::<&'a isize>(); //~ ERROR does not fulfill the required lifetime
}
fn test21<'a>(_: &'a isize) {
assert_send::<&'a str>(); //~ ERROR does not fulfill the required lifetime
}
fn test22<'a>(_: &'a isize) {
assert_send::<&'a [isize]>(); //~ ERROR does not fulfill the required lifetime
}
fn main() { }

View file

@ -1,83 +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.
// Test which of the builtin types are considered sendable. The tests
// in this file all test region bound and lifetime violations that are
// detected during type check.
extern crate core;
use core::ptr::Unique;
fn assert_send<T:Send>() { }
trait Dummy:Send { }
// lifetime pointers with 'static lifetime are ok
fn static_lifime_ok<'a,T,U:Send>(_: &'a isize) {
assert_send::<&'static isize>();
assert_send::<&'static str>();
assert_send::<&'static [isize]>();
// whether or not they are mutable
assert_send::<&'static mut isize>();
}
// otherwise lifetime pointers are not ok
fn param_not_ok<'a>(x: &'a isize) {
assert_send::<&'a isize>(); //~ ERROR does not fulfill the required lifetime
}
fn param_not_ok1<'a>(_: &'a isize) {
assert_send::<&'a str>(); //~ ERROR does not fulfill the required lifetime
}
fn param_not_ok2<'a>(_: &'a isize) {
assert_send::<&'a [isize]>(); //~ ERROR does not fulfill the required lifetime
}
// boxes are ok
fn box_ok() {
assert_send::<Box<isize>>();
assert_send::<String>();
assert_send::<Vec<isize>>();
}
// but not if they own a bad thing
fn box_with_region_not_ok<'a>() {
assert_send::<Box<&'a isize>>(); //~ ERROR does not fulfill the required lifetime
}
// objects with insufficient bounds no ok
fn object_with_random_bound_not_ok<'a>() {
assert_send::<&'a (Dummy+'a)>();
//~^ ERROR reference has a longer lifetime
}
fn object_with_send_bound_not_ok<'a>() {
assert_send::<&'a (Dummy+Send)>();
//~^ ERROR does not fulfill the required lifetime
}
// unsafe pointers are ok unless they point at unsendable things
struct UniqueUnsafePtr(Unique<*const isize>);
unsafe impl Send for UniqueUnsafePtr {}
fn unsafe_ok1<'a>(_: &'a isize) {
assert_send::<UniqueUnsafePtr>();
}
fn main() {
}

View file

@ -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); }
}
}

View file

@ -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();
}

View file

@ -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
}