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 
denormalise<'a, T>(t: &'a T) -> <T as Foo<'a>>::Bar13 fn denormalise<'a, T>(t: &'a T) -> <T as Foo<'a>>::Bar {
14     t
15 }
16 
free_and_use<T: for<'a> Foo<'a>, F: for<'a> FnOnce(<T as Foo<'a>>::Bar)>(x: T, f: F)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 
main()27 pub fn main() {
28 }
29