]> git.proxmox.com Git - rustc.git/blame - src/test/run-pass/issues/issue-24805-dropck-itemless.rs
New upstream version 1.33.0+dfsg1
[rustc.git] / src / test / run-pass / issues / issue-24805-dropck-itemless.rs
CommitLineData
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
11trait UserDefined { }
12
13impl UserDefined for i32 { }
14impl<'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// ```
21macro_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
31impl_drop!{Send, D_Send}
32impl_drop!{Sized, D_Sized}
33
34// See note below regarding Issue 24895
35// impl_drop!{Copy, D_Copy}
36
37impl_drop!{Sync, D_Sync}
38impl_drop!{UserDefined, D_UserDefined}
39
40macro_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
54fn f_send() { body!(D_Send) }
55fn f_sized() { body!(D_Sized) }
56fn 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
70fn f_userdefined() { body!(D_UserDefined) }
71
72fn main() {
73 f_send();
74 f_sized();
75 // See note above regarding Issue 24895.
76 // f_copy();
77 f_sync();
78 f_userdefined();
79}