]> git.proxmox.com Git - rustc.git/blob - src/test/ui/dropck/dropck_traits.rs
New upstream version 1.66.0+dfsg1
[rustc.git] / src / test / ui / dropck / dropck_traits.rs
1 // run-pass
2 //! Regression test for #34426, regarding HRTB in drop impls
3
4 // All of this Drop impls should compile.
5
6 pub trait Lifetime<'a> {}
7 impl<'a> Lifetime<'a> for i32 {}
8
9 #[allow(dead_code)]
10 struct Foo<L>
11 where
12 for<'a> L: Lifetime<'a>,
13 {
14 l: L,
15 }
16
17 impl<L> Drop for Foo<L>
18 where
19 for<'a> L: Lifetime<'a>,
20 {
21 fn drop(&mut self) {}
22 }
23
24 #[allow(dead_code)]
25 struct Foo2<L>
26 where
27 for<'a> L: Lifetime<'a>,
28 {
29 l: L,
30 }
31
32 impl<T: for<'a> Lifetime<'a>> Drop for Foo2<T>
33 where
34 for<'x> T: Lifetime<'x>,
35 {
36 fn drop(&mut self) {}
37 }
38
39 pub trait Lifetime2<'a, 'b> {}
40 impl<'a, 'b> Lifetime2<'a, 'b> for i32 {}
41
42 #[allow(dead_code)]
43 struct Bar<L>
44 where
45 for<'a, 'b> L: Lifetime2<'a, 'b>,
46 {
47 l: L,
48 }
49
50 impl<L> Drop for Bar<L>
51 where
52 for<'a, 'b> L: Lifetime2<'a, 'b>,
53 {
54 fn drop(&mut self) {}
55 }
56
57 #[allow(dead_code)]
58 struct FnHolder<T: for<'a> Fn(&'a T, dyn for<'b> Lifetime2<'a, 'b>) -> u8>(T);
59
60 impl<T: for<'a> Fn(&'a T, dyn for<'b> Lifetime2<'a, 'b>) -> u8> Drop for FnHolder<T> {
61 fn drop(&mut self) {}
62 }
63
64 fn main() {
65 let _foo = Foo { l: 0 };
66
67 let _bar = Bar { l: 0 };
68 }