]> git.lizzy.rs Git - rust.git/blob - src/test/ui/kindck/kindck-send-object1.rs
Migrate diagnostics in parser/expr to SessionDiagnostic
[rust.git] / src / test / ui / kindck / kindck-send-object1.rs
1 // Test which object types are considered sendable. This test
2 // is broken into two parts because some errors occur in distinct
3 // phases in the compiler. See kindck-send-object2.rs as well!
4
5 fn assert_send<T:Send+'static>() { }
6 trait Dummy { }
7
8 // careful with object types, who knows what they close over...
9 fn test51<'a>() {
10     assert_send::<&'a dyn Dummy>();
11     //~^ ERROR `(dyn Dummy + 'a)` cannot be shared between threads safely [E0277]
12 }
13 fn test52<'a>() {
14     assert_send::<&'a (dyn Dummy + Sync)>();
15 }
16
17 // ...unless they are properly bounded
18 fn test60() {
19     assert_send::<&'static (dyn Dummy + Sync)>();
20 }
21 fn test61() {
22     assert_send::<Box<dyn Dummy + Send>>();
23 }
24
25 // closure and object types can have lifetime bounds which make
26 // them not ok
27 fn test_71<'a>() {
28     assert_send::<Box<dyn Dummy + 'a>>();
29     //~^ ERROR `(dyn Dummy + 'a)` cannot be sent between threads safely
30 }
31
32 fn main() { }