]> git.lizzy.rs Git - rust.git/blob - src/test/ui/issues/issue-18937-1.rs
Merge commit '97e504549371d7640cf011d266e3c17394fdddac' into sync_cg_clif-2021-12-20
[rust.git] / src / test / ui / issues / issue-18937-1.rs
1 // run-pass
2 // Test that we are able to type-check this example. In particular,
3 // knowing that `T: 'a` allows us to deduce that `[U]: 'a` (because
4 // when `T=[U]` it implies that `U: 'a`).
5 //
6 // Regr. test for live code we found in the wild when fixing #18937.
7
8 pub trait Leak<T : ?Sized> {
9     fn leak<'a>(self) -> &'a T where T: 'a;
10 }
11
12 impl<U> Leak<[U]> for Vec<U> {
13     fn leak<'a>(mut self) -> &'a [U] where [U]: 'a {
14         let r: *mut [U] = &mut self[..];
15         std::mem::forget(self);
16         unsafe { &mut *r }
17     }
18 }
19 fn main() {
20     println!("Hello, world!");
21 }