1 // Issue 8142: Test that Drop impls cannot be specialized beyond the
2 // predicates attached to the type definition itself.
3 #![feature(min_const_generics)]
5 trait Bound { fn foo(&self) { } }
6 struct K<'l1,'l2> { x: &'l1 i8, y: &'l2 u8 }
7 struct L<'l1,'l2> { x: &'l1 i8, y: &'l2 u8 }
8 struct M<'m> { x: &'m i8 }
9 struct N<'n> { x: &'n i8 }
10 struct O<To> { x: *const To }
11 struct P<Tp> { x: *const Tp }
12 struct Q<Tq> { x: *const Tq }
13 struct R<Tr> { x: *const Tr }
14 struct S<Ts:Bound> { x: *const Ts }
15 struct T<'t,Ts:'t> { x: &'t Ts }
17 struct V<Tva, Tvb> { x: *const Tva, y: *const Tvb }
18 struct W<'l1, 'l2> { x: &'l1 i8, y: &'l2 u8 }
19 struct X<const Ca: usize>;
20 struct Y<const Ca: usize, const Cb: usize>;
22 enum Enum<T> { Variant(T) }
23 struct TupleStruct<T>(T);
24 union Union<T: Copy> { f: T }
26 impl<'al,'adds_bnd:'al> Drop for K<'al,'adds_bnd> { // REJECT
27 //~^ ERROR `Drop` impl requires `'adds_bnd: 'al`
28 fn drop(&mut self) { } }
30 impl<'al,'adds_bnd> Drop for L<'al,'adds_bnd> where 'adds_bnd:'al { // REJECT
31 //~^ ERROR `Drop` impl requires `'adds_bnd: 'al`
32 fn drop(&mut self) { } }
34 impl<'ml> Drop for M<'ml> { fn drop(&mut self) { } } // ACCEPT
36 impl Drop for N<'static> { fn drop(&mut self) { } } // REJECT
37 //~^ ERROR mismatched types
38 //~| expected struct `N<'n>`
39 //~| found struct `N<'static>`
41 impl<COkNoBound> Drop for O<COkNoBound> { fn drop(&mut self) { } } // ACCEPT
43 impl Drop for P<i8> { fn drop(&mut self) { } } // REJECT
44 //~^ ERROR `Drop` impls cannot be specialized
46 impl<AddsBnd:Bound> Drop for Q<AddsBnd> { fn drop(&mut self) { } } // REJECT
47 //~^ ERROR `Drop` impl requires `AddsBnd: Bound`
49 impl<'rbnd,AddsRBnd:'rbnd> Drop for R<AddsRBnd> { fn drop(&mut self) { } } // REJECT
50 //~^ ERROR `Drop` impl requires `AddsRBnd: 'rbnd`
52 impl<Bs:Bound> Drop for S<Bs> { fn drop(&mut self) { } } // ACCEPT
54 impl<'t,Bt:'t> Drop for T<'t,Bt> { fn drop(&mut self) { } } // ACCEPT
56 impl Drop for U { fn drop(&mut self) { } } // ACCEPT
58 impl<One> Drop for V<One,One> { fn drop(&mut self) { } } // REJECT
59 //~^ ERROR `Drop` impls cannot be specialized
61 impl<'lw> Drop for W<'lw,'lw> { fn drop(&mut self) { } } // REJECT
62 //~^ ERROR cannot infer an appropriate lifetime for lifetime parameter `'lw`
64 impl Drop for X<3> { fn drop(&mut self) { } } // REJECT
65 //~^ ERROR `Drop` impls cannot be specialized
67 impl<const Ca: usize> Drop for Y<Ca, Ca> { fn drop(&mut self) { } } // REJECT
68 //~^ ERROR `Drop` impls cannot be specialized
70 impl<AddsBnd:Bound> Drop for Enum<AddsBnd> { fn drop(&mut self) { } } // REJECT
71 //~^ ERROR `Drop` impl requires `AddsBnd: Bound`
73 impl<AddsBnd:Bound> Drop for TupleStruct<AddsBnd> { fn drop(&mut self) { } } // REJECT
74 //~^ ERROR `Drop` impl requires `AddsBnd: Bound`
76 impl<AddsBnd:Copy + Bound> Drop for Union<AddsBnd> { fn drop(&mut self) { } } // REJECT
77 //~^ ERROR `Drop` impl requires `AddsBnd: Bound`