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