rust/src/test/compile-fail/kindck-send.rs
Patrick Walton 9b9ef44233 libsyntax: Allow + to separate trait bounds from objects.
RFC #27.

After a snapshot, the old syntax will be removed.

This can break some code that looked like `foo as &Trait:Send`. Now you
will need to write `foo as (&Trait+Send)`.

Closes #12778.

[breaking-change]
2014-06-13 13:53:34 -07:00

61 lines
2.2 KiB
Rust

// 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.
fn assert_send<T:Send>() { }
trait Dummy { }
fn test<'a,T,U:Send>(_: &'a int) {
// lifetime pointers with 'static lifetime are ok
assert_send::<&'static int>();
assert_send::<&'static str>();
assert_send::<&'static [int]>();
// whether or not they are mutable
assert_send::<&'static mut int>();
// otherwise lifetime pointers are not ok
assert_send::<&'a int>(); //~ ERROR does not fulfill `Send`
assert_send::<&'a str>(); //~ ERROR does not fulfill `Send`
assert_send::<&'a [int]>(); //~ ERROR does not fulfill `Send`
// boxes are ok
assert_send::<Box<int>>();
assert_send::<String>();
assert_send::<Vec<int> >();
// but not if they own a bad thing
assert_send::<Box<&'a int>>(); //~ ERROR does not fulfill `Send`
// careful with object types, who knows what they close over...
assert_send::<&'static Dummy>(); //~ ERROR does not fulfill `Send`
assert_send::<&'a Dummy>(); //~ ERROR does not fulfill `Send`
assert_send::<&'a Dummy+Send>(); //~ ERROR does not fulfill `Send`
assert_send::<Box<Dummy+>>(); //~ ERROR does not fulfill `Send`
// ...unless they are properly bounded
assert_send::<&'static Dummy+Send>();
assert_send::<Box<Dummy+Send>>();
// but closure and object types can have lifetime bounds which make
// them not ok (FIXME #5121)
// assert_send::<proc:'a()>(); // ERROR does not fulfill `Send`
// assert_send::<Box<Dummy+'a>>(); // ERROR does not fulfill `Send`
// unsafe ptrs are ok unless they point at unsendable things
assert_send::<*int>();
assert_send::<*&'a int>(); //~ ERROR does not fulfill `Send`
}
fn main() {
}