]> git.lizzy.rs Git - rust.git/blob - src/test/ui/traits/traits-negative-impls.rs
fb9a3a99748d02d4c222d656f9f48a5774db7c71
[rust.git] / src / test / ui / traits / traits-negative-impls.rs
1 // The dummy functions are used to avoid adding new cfail files.
2 // What happens is that the compiler attempts to squash duplicates and some
3 // errors are not reported. This way, we make sure that, for each function, different
4 // typeck phases are involved and all errors are reported.
5
6 #![feature(optin_builtin_traits)]
7
8 use std::marker::Send;
9
10 struct Outer<T: Send>(T);
11
12 struct Outer2<T>(T);
13
14 unsafe impl<T: Send> Sync for Outer2<T> {}
15
16 fn is_send<T: Send>(_: T) {}
17 fn is_sync<T: Sync>(_: T) {}
18
19 fn dummy() {
20     struct TestType;
21     impl !Send for TestType {}
22
23     Outer(TestType);
24     //~^ ERROR `dummy::TestType` cannot be sent between threads safely
25     //~| ERROR `dummy::TestType` cannot be sent between threads safely
26 }
27
28 fn dummy1b() {
29     struct TestType;
30     impl !Send for TestType {}
31
32     is_send(TestType);
33     //~^ ERROR `dummy1b::TestType` cannot be sent between threads safely
34 }
35
36 fn dummy1c() {
37     struct TestType;
38     impl !Send for TestType {}
39
40     is_send((8, TestType));
41     //~^ ERROR `dummy1c::TestType` cannot be sent between threads safely
42 }
43
44 fn dummy2() {
45     struct TestType;
46     impl !Send for TestType {}
47
48     is_send(Box::new(TestType));
49     //~^ ERROR `dummy2::TestType` cannot be sent between threads safely
50 }
51
52 fn dummy3() {
53     struct TestType;
54     impl !Send for TestType {}
55
56     is_send(Box::new(Outer2(TestType)));
57     //~^ ERROR `dummy3::TestType` cannot be sent between threads safely
58 }
59
60 fn main() {
61     struct TestType;
62     impl !Send for TestType {}
63
64     // This will complain about a missing Send impl because `Sync` is implement *just*
65     // for T that are `Send`. Look at #20366 and #19950
66     is_sync(Outer2(TestType));
67     //~^ ERROR `main::TestType` cannot be sent between threads safely
68 }