1 #![feature(unboxed_closures)]
2 // Test for projection cache. We should be able to project distinct
3 // lifetimes from `foo` as we reinstantiate it multiple times, but not
4 // if we do it just once. In this variant, the region `'a` is used in
5 // an invariant position, which affects the results.
7 // revisions: ok oneuse transmute krisskross
10 #![allow(dead_code, unused_variables)]
12 use std::marker::PhantomData;
16 data: PhantomData<fn(&'a u32) -> &'a u32>,
19 fn foo<'a>() -> Type<'a> {
23 fn bar<T>(t: T, x: T::Output) -> T::Output
30 #[cfg(ok)] // two instantiations: OK
31 fn baz<'a, 'b>(x: Type<'a>, y: Type<'b>) -> (Type<'a>, Type<'b>) {
37 #[cfg(oneuse)] // one instantiation: BAD
38 fn baz<'a, 'b>(x: Type<'a>, y: Type<'b>) -> (Type<'a>, Type<'b>) {
39 let f = foo; // <-- No consistent type can be inferred for `f` here.
41 //[oneuse]~^ ERROR lifetime may not live long enough
42 //[oneuse]~| ERROR lifetime may not live long enough
47 #[cfg(transmute)] // one instantiations: BAD
48 fn baz<'a, 'b>(x: Type<'a>) -> Type<'static> {
49 // Cannot instantiate `foo` with any lifetime other than `'a`,
50 // since it is provided as input.
52 bar(foo, x) //[transmute]~ ERROR lifetime may not live long enough
55 #[cfg(krisskross)] // two instantiations, mixing and matching: BAD
56 fn transmute<'a, 'b>(x: Type<'a>, y: Type<'b>) -> (Type<'a>, Type<'b>) {
60 //[krisskross]~^ ERROR lifetime may not live long enough
61 //[krisskross]~| ERROR lifetime may not live long enough