]> git.lizzy.rs Git - rust.git/blob - src/test/ui/impl-trait/multiple-lifetimes/error-handling-2.rs
Check that RPITs constrained by a recursive call in a closure are compatible
[rust.git] / src / test / ui / impl-trait / multiple-lifetimes / error-handling-2.rs
1 #![feature(type_alias_impl_trait)]
2
3 #[derive(Clone)]
4 struct CopyIfEq<T, U>(T, U);
5
6 impl<T: Copy> Copy for CopyIfEq<T, T> {}
7
8 type E<'a, 'b> = impl Sized;
9
10 fn foo<'a: 'b, 'b, 'c>(x: &'static i32, mut y: &'a i32) -> E<'b, 'c> {
11     let v = CopyIfEq::<*mut _, *mut _>(&mut { x }, &mut y);
12
13     // This assignment requires that `x` and `y` have the same type due to the
14     // `Copy` impl. The reason why we are using a copy to create a constraint
15     // is that only borrow checking (not regionck in type checking) enforces
16     // this bound.
17     let u = v;
18     let _: *mut &'a i32 = u.1;
19     unsafe {
20         let _: &'b i32 = *u.0;
21     }
22     u.0
23     //~^ ERROR hidden type for `impl Trait` captures lifetime that does not appear in bounds
24 }
25
26 fn main() {}