]> git.lizzy.rs Git - rust.git/blob - src/test/ui/reject-specialized-drops-8142.rs
Auto merge of #62748 - luca-barbieri:optimize-refcell-borrow, r=RalfJung
[rust.git] / src / test / ui / reject-specialized-drops-8142.rs
1 // Issue 8142: Test that Drop impls cannot be specialized beyond the
2 // predicates attached to the struct/enum definition itself.
3
4 trait Bound { fn foo(&self) { } }
5 struct K<'l1,'l2> { x: &'l1 i8, y: &'l2 u8 }
6 struct L<'l1,'l2> { x: &'l1 i8, y: &'l2 u8 }
7 struct M<'m> { x: &'m i8 }
8 struct N<'n> { x: &'n i8 }
9 struct O<To> { x: *const To }
10 struct P<Tp> { x: *const Tp }
11 struct Q<Tq> { x: *const Tq }
12 struct R<Tr> { x: *const Tr }
13 struct S<Ts:Bound> { x: *const Ts }
14 struct T<'t,Ts:'t> { x: &'t Ts }
15 struct U;
16 struct V<Tva, Tvb> { x: *const Tva, y: *const Tvb }
17 struct W<'l1, 'l2> { x: &'l1 i8, y: &'l2 u8 }
18
19 impl<'al,'adds_bnd:'al> Drop for K<'al,'adds_bnd> {                        // REJECT
20     //~^ ERROR The requirement `'adds_bnd : 'al` is added only by the Drop impl.
21     fn drop(&mut self) { } }
22
23 impl<'al,'adds_bnd>     Drop for L<'al,'adds_bnd> where 'adds_bnd:'al {    // REJECT
24     //~^ ERROR The requirement `'adds_bnd : 'al` is added only by the Drop impl.
25     fn drop(&mut self) { } }
26
27 impl<'ml>               Drop for M<'ml>         { fn drop(&mut self) { } } // ACCEPT
28
29 impl                    Drop for N<'static>     { fn drop(&mut self) { } } // REJECT
30 //~^ ERROR mismatched types
31 //~| expected type `N<'n>`
32 //~|    found type `N<'static>`
33
34 impl<COkNoBound> Drop for O<COkNoBound> { fn drop(&mut self) { } } // ACCEPT
35
36 impl              Drop for P<i8>          { fn drop(&mut self) { } } // REJECT
37 //~^ ERROR Implementations of Drop cannot be specialized
38
39 impl<AddsBnd:Bound> Drop for Q<AddsBnd> { fn drop(&mut self) { } } // REJECT
40 //~^ ERROR The requirement `AddsBnd: Bound` is added only by the Drop impl.
41
42 impl<'rbnd,AddsRBnd:'rbnd> Drop for R<AddsRBnd> { fn drop(&mut self) { } } // REJECT
43 //~^ ERROR The requirement `AddsRBnd : 'rbnd` is added only by the Drop impl.
44
45 impl<Bs:Bound>    Drop for S<Bs>          { fn drop(&mut self) { } } // ACCEPT
46
47 impl<'t,Bt:'t>    Drop for T<'t,Bt>       { fn drop(&mut self) { } } // ACCEPT
48
49 impl              Drop for U              { fn drop(&mut self) { } } // ACCEPT
50
51 impl<One>         Drop for V<One,One>     { fn drop(&mut self) { } } // REJECT
52 //~^ ERROR Implementations of Drop cannot be specialized
53
54 impl<'lw>         Drop for W<'lw,'lw>     { fn drop(&mut self) { } } // REJECT
55 //~^ ERROR cannot infer an appropriate lifetime
56
57 pub fn main() { }