]> git.proxmox.com Git - rustc.git/blob - src/test/ui/impl-trait/multiple-lifetimes/error-handling.rs
8d02d635094be46c270d8eae84c6cc303fc9f005
[rustc.git] / src / test / ui / impl-trait / multiple-lifetimes / error-handling.rs
1 // compile-flags:-Zborrowck=mir
2
3 #![feature(member_constraints)]
4 #![feature(type_alias_impl_trait)]
5
6 #[derive(Clone)]
7 struct CopyIfEq<T, U>(T, U);
8
9 impl<T: Copy> Copy for CopyIfEq<T, T> {}
10
11 type E<'a, 'b> = impl Sized;
12
13 fn foo<'a, 'b, 'c>(x: &'static i32, mut y: &'a i32) -> E<'b, 'c> {
14 let v = CopyIfEq::<*mut _, *mut _>(&mut { x }, &mut y);
15
16 // This assignment requires that `x` and `y` have the same type due to the
17 // `Copy` impl. The reason why we are using a copy to create a constraint
18 // is that only borrow checking (not regionck in type checking) enforces
19 // this bound.
20 let u = v;
21 let _: *mut &'a i32 = u.1;
22 unsafe {
23 let _: &'b i32 = *u.0;
24 //~^ ERROR lifetime may not live long enough
25 }
26 u.0
27 }
28
29 fn main() {}