]>
Commit | Line | Data |
---|---|---|
b7449926 XL |
1 | // run-pass |
2 | #![allow(deprecated)] | |
3 | ||
d9579d0f AL |
4 | // Check that item-less traits do not cause dropck to inject extra |
5 | // region constraints. | |
6 | ||
7 | #![allow(non_camel_case_types)] | |
8 | ||
b039eaaf SL |
9 | #![feature(dropck_parametricity)] |
10 | ||
d9579d0f AL |
11 | trait UserDefined { } |
12 | ||
13 | impl UserDefined for i32 { } | |
14 | impl<'a, T> UserDefined for &'a T { } | |
15 | ||
0731742a | 16 | // e.g., `impl_drop!(Send, D_Send)` expands to: |
d9579d0f AL |
17 | // ```rust |
18 | // struct D_Send<T:Send>(T); | |
19 | // impl<T:Send> Drop for D_Send<T> { fn drop(&mut self) { } } | |
20 | // ``` | |
21 | macro_rules! impl_drop { | |
22 | ($Bound:ident, $Id:ident) => { | |
23 | struct $Id<T:$Bound>(T); | |
b039eaaf SL |
24 | impl <T:$Bound> Drop for $Id<T> { |
25 | #[unsafe_destructor_blind_to_params] | |
26 | fn drop(&mut self) { } | |
27 | } | |
d9579d0f AL |
28 | } |
29 | } | |
30 | ||
31 | impl_drop!{Send, D_Send} | |
32 | impl_drop!{Sized, D_Sized} | |
33 | ||
34 | // See note below regarding Issue 24895 | |
35 | // impl_drop!{Copy, D_Copy} | |
36 | ||
37 | impl_drop!{Sync, D_Sync} | |
38 | impl_drop!{UserDefined, D_UserDefined} | |
39 | ||
40 | macro_rules! body { | |
41 | ($id:ident) => { { | |
42 | // `_d` and `d1` are assigned the *same* lifetime by region inference ... | |
43 | let (_d, d1); | |
44 | ||
45 | d1 = $id(1); | |
46 | // ... we store a reference to `d1` within `_d` ... | |
47 | _d = $id(&d1); | |
48 | ||
49 | // ... a *conservative* dropck will thus complain, because it | |
50 | // thinks Drop of _d could access the already dropped `d1`. | |
51 | } } | |
52 | } | |
53 | ||
54 | fn f_send() { body!(D_Send) } | |
55 | fn f_sized() { body!(D_Sized) } | |
56 | fn f_sync() { body!(D_Sync) } | |
57 | ||
58 | // Issue 24895: Copy: Clone implies `impl<T:Copy> Drop for ...` can | |
59 | // access a user-defined clone() method, which causes this test case | |
60 | // to fail. | |
61 | // | |
62 | // If 24895 is resolved by removing the `Copy: Clone` relationship, | |
63 | // then this definition and the call below should be uncommented. If | |
64 | // it is resolved by deciding to keep the `Copy: Clone` relationship, | |
65 | // then this comment and the associated bits of code can all be | |
66 | // removed. | |
67 | ||
68 | // fn f_copy() { body!(D_Copy) } | |
69 | ||
70 | fn f_userdefined() { body!(D_UserDefined) } | |
71 | ||
72 | fn main() { | |
73 | f_send(); | |
74 | f_sized(); | |
75 | // See note above regarding Issue 24895. | |
76 | // f_copy(); | |
77 | f_sync(); | |
78 | f_userdefined(); | |
79 | } |