]> git.lizzy.rs Git - rust.git/blob - src/test/ui/dropck/reject-specialized-drops-8142.rs
Merge commit '3e7c6dec244539970b593824334876f8b6ed0b18' into clippyup
[rust.git] / src / test / 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 #![feature(min_const_generics)]
4
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 }
16 struct U;
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>;
21
22 enum Enum<T> { Variant(T) }
23 struct TupleStruct<T>(T);
24 union Union<T: Copy> { f: T }
25
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) { } }
29
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) { } }
33
34 impl<'ml>               Drop for M<'ml>         { fn drop(&mut self) { } } // ACCEPT
35
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>`
40
41 impl<COkNoBound> Drop for O<COkNoBound> { fn drop(&mut self) { } } // ACCEPT
42
43 impl              Drop for P<i8>          { fn drop(&mut self) { } } // REJECT
44 //~^ ERROR `Drop` impls cannot be specialized
45
46 impl<AddsBnd:Bound> Drop for Q<AddsBnd> { fn drop(&mut self) { } } // REJECT
47 //~^ ERROR `Drop` impl requires `AddsBnd: Bound`
48
49 impl<'rbnd,AddsRBnd:'rbnd> Drop for R<AddsRBnd> { fn drop(&mut self) { } } // REJECT
50 //~^ ERROR `Drop` impl requires `AddsRBnd: 'rbnd`
51
52 impl<Bs:Bound>    Drop for S<Bs>          { fn drop(&mut self) { } } // ACCEPT
53
54 impl<'t,Bt:'t>    Drop for T<'t,Bt>       { fn drop(&mut self) { } } // ACCEPT
55
56 impl              Drop for U              { fn drop(&mut self) { } } // ACCEPT
57
58 impl<One>         Drop for V<One,One>     { fn drop(&mut self) { } } // REJECT
59 //~^ ERROR `Drop` impls cannot be specialized
60
61 impl<'lw>         Drop for W<'lw,'lw>     { fn drop(&mut self) { } } // REJECT
62 //~^ ERROR cannot infer an appropriate lifetime for lifetime parameter `'lw`
63
64 impl              Drop for X<3>           { fn drop(&mut self) { } } // REJECT
65 //~^ ERROR `Drop` impls cannot be specialized
66
67 impl<const Ca: usize> Drop for Y<Ca, Ca>     { fn drop(&mut self) { } } // REJECT
68 //~^ ERROR `Drop` impls cannot be specialized
69
70 impl<AddsBnd:Bound> Drop for Enum<AddsBnd> { fn drop(&mut self) { } } // REJECT
71 //~^ ERROR `Drop` impl requires `AddsBnd: Bound`
72
73 impl<AddsBnd:Bound> Drop for TupleStruct<AddsBnd> { fn drop(&mut self) { } } // REJECT
74 //~^ ERROR `Drop` impl requires `AddsBnd: Bound`
75
76 impl<AddsBnd:Copy + Bound> Drop for Union<AddsBnd> { fn drop(&mut self) { } } // REJECT
77 //~^ ERROR `Drop` impl requires `AddsBnd: Bound`
78
79 pub fn main() { }