]> git.lizzy.rs Git - rust.git/blob - src/test/ui/associated-types/associated-types-outlives.rs
feat(rustdoc): open sidebar menu when links inside it are focused
[rust.git] / src / test / ui / associated-types / associated-types-outlives.rs
1 // Regression test for issue #24622. The older associated types code
2 // was erroneously assuming that all projections outlived the current
3 // fn body, causing this (invalid) code to be accepted.
4
5 pub trait Foo<'a> {
6     type Bar;
7 }
8
9 impl<'a, T:'a> Foo<'a> for T {
10     type Bar = &'a T;
11 }
12
13 fn denormalise<'a, T>(t: &'a T) -> <T as Foo<'a>>::Bar {
14     t
15 }
16
17 pub fn free_and_use<T: for<'a> Foo<'a>,
18                     F: for<'a> FnOnce(<T as Foo<'a>>::Bar)>(x: T, f: F) {
19     let y;
20     'body: loop { // lifetime annotations added for clarity
21         's: loop { y = denormalise(&x); break }
22         drop(x); //~ ERROR cannot move out of `x` because it is borrowed
23         return f(y);
24     }
25 }
26
27 pub fn main() {
28 }