]> git.lizzy.rs Git - rust.git/blob - src/test/ui/variance/variance-issue-20533.rs
Rollup merge of #94248 - compiler-errors:fix-while-loop-bad-delay, r=petrochenkov
[rust.git] / src / test / ui / variance / variance-issue-20533.rs
1 // Regression test for issue #20533. At some point, only 1 out of the
2 // 3 errors below were being reported.
3
4 use std::marker::PhantomData;
5
6 fn foo<'a, T>(_x: &'a T) -> PhantomData<&'a ()> {
7     PhantomData
8 }
9
10 struct Wrap<T>(T);
11
12 fn bar<'a, T>(_x: &'a T) -> Wrap<PhantomData<&'a ()>> {
13     Wrap(PhantomData)
14 }
15
16 struct Baked<'a>(PhantomData<&'a ()>);
17
18 fn baz<'a, T>(_x: &'a T) -> Baked<'a> {
19     Baked(PhantomData)
20 }
21
22 struct AffineU32(u32);
23
24 fn main() {
25     {
26         let a = AffineU32(1);
27         let x = foo(&a);
28         drop(a); //~ ERROR cannot move out of `a`
29         drop(x);
30     }
31     {
32         let a = AffineU32(1);
33         let x = bar(&a);
34         drop(a); //~ ERROR cannot move out of `a`
35         drop(x);
36     }
37     {
38         let a = AffineU32(1);
39         let x = baz(&a);
40         drop(a); //~ ERROR cannot move out of `a`
41         drop(x);
42     }
43 }