]> git.lizzy.rs Git - rust.git/blob - tests/ui/dropck/reject-specialized-drops-8142.rs
Rollup merge of #106797 - FawazTirmizi:dev/issues/104284, r=bjorn3
[rust.git] / tests / ui / dropck / reject-specialized-drops-8142.rs
1 // Issue 8142: Test that Drop impls cannot be specialized beyond the
2 // predicates attached to the type definition itself.
3 trait Bound { fn foo(&self) { } }
4 struct K<'l1,'l2> { x: &'l1 i8, y: &'l2 u8 }
5 struct L<'l1,'l2> { x: &'l1 i8, y: &'l2 u8 }
6 struct M<'m> { x: &'m i8 }
7 struct N<'n> { x: &'n i8 }
8 struct O<To> { x: *const To }
9 struct P<Tp> { x: *const Tp }
10 struct Q<Tq> { x: *const Tq }
11 struct R<Tr> { x: *const Tr }
12 struct S<Ts:Bound> { x: *const Ts }
13 struct T<'t,Ts:'t> { x: &'t Ts }
14 struct U;
15 struct V<Tva, Tvb> { x: *const Tva, y: *const Tvb }
16 struct W<'l1, 'l2> { x: &'l1 i8, y: &'l2 u8 }
17 struct X<const Ca: usize>;
18 struct Y<const Ca: usize, const Cb: usize>;
19
20 enum Enum<T> { Variant(T) }
21 struct TupleStruct<T>(T);
22 union Union<T: Copy> { f: T }
23
24 impl<'al,'adds_bnd:'al> Drop for K<'al,'adds_bnd> {                        // REJECT
25     //~^ ERROR `Drop` impl requires `'adds_bnd: 'al`
26     fn drop(&mut self) { } }
27
28 impl<'al,'adds_bnd>     Drop for L<'al,'adds_bnd> where 'adds_bnd:'al {    // REJECT
29     //~^ ERROR `Drop` impl requires `'adds_bnd: 'al`
30     fn drop(&mut self) { } }
31
32 impl<'ml>               Drop for M<'ml>         { fn drop(&mut self) { } } // ACCEPT
33
34 impl                    Drop for N<'static>     { fn drop(&mut self) { } } // REJECT
35 //~^ ERROR `Drop` impls cannot be specialized
36
37 impl<COkNoBound> Drop for O<COkNoBound> { fn drop(&mut self) { } } // ACCEPT
38
39 impl              Drop for P<i8>          { fn drop(&mut self) { } } // REJECT
40 //~^ ERROR `Drop` impls cannot be specialized
41
42 impl<AddsBnd:Bound> Drop for Q<AddsBnd> { fn drop(&mut self) { } } // REJECT
43 //~^ ERROR `Drop` impl requires `AddsBnd: Bound`
44
45 impl<'rbnd,AddsRBnd:'rbnd> Drop for R<AddsRBnd> { fn drop(&mut self) { } } // REJECT
46 //~^ ERROR `Drop` impl requires `AddsRBnd: 'rbnd`
47
48 impl<Bs:Bound>    Drop for S<Bs>          { fn drop(&mut self) { } } // ACCEPT
49
50 impl<'t,Bt:'t>    Drop for T<'t,Bt>       { fn drop(&mut self) { } } // ACCEPT
51
52 impl              Drop for U              { fn drop(&mut self) { } } // ACCEPT
53
54 impl<One>         Drop for V<One,One>     { fn drop(&mut self) { } } // REJECT
55 //~^ ERROR `Drop` impls cannot be specialized
56
57 impl<'lw>         Drop for W<'lw,'lw>     { fn drop(&mut self) { } } // REJECT
58 //~^ ERROR `Drop` impls cannot be specialized
59
60 impl              Drop for X<3>           { fn drop(&mut self) { } } // REJECT
61 //~^ ERROR `Drop` impls cannot be specialized
62
63 impl<const Ca: usize> Drop for Y<Ca, Ca>     { fn drop(&mut self) { } } // REJECT
64 //~^ ERROR `Drop` impls cannot be specialized
65
66 impl<AddsBnd:Bound> Drop for Enum<AddsBnd> { fn drop(&mut self) { } } // REJECT
67 //~^ ERROR `Drop` impl requires `AddsBnd: Bound`
68
69 impl<AddsBnd:Bound> Drop for TupleStruct<AddsBnd> { fn drop(&mut self) { } } // REJECT
70 //~^ ERROR `Drop` impl requires `AddsBnd: Bound`
71
72 impl<AddsBnd:Copy + Bound> Drop for Union<AddsBnd> { fn drop(&mut self) { } } // REJECT
73 //~^ ERROR `Drop` impl requires `AddsBnd: Bound`
74
75 pub fn main() { }