1 A lifetime bound on a trait implementation was captured at an incorrect place.
3 Erroneous code example:
9 impl<'a> Lt<'a> for () {}
10 impl<T> Id<T> for T {}
12 fn free_fn_capture_hrtb_in_impl_trait()
13 -> Box<for<'a> Id<impl Lt<'a>>> // error!
20 fn impl_fn_capture_hrtb_in_impl_trait()
21 -> Box<for<'a> Id<impl Lt<'a>>> // error!
28 Here, you have used the inappropriate lifetime in the `impl Trait`,
29 The `impl Trait` can only capture lifetimes bound at the fn or impl
32 To fix this we have to define the lifetime at the function or impl
33 level and use that lifetime in the `impl Trait`. For example you can
34 define the lifetime at the function:
40 impl<'a> Lt<'a> for () {}
41 impl<T> Id<T> for T {}
43 fn free_fn_capture_hrtb_in_impl_trait<'b>()
44 -> Box<for<'a> Id<impl Lt<'b>>> // ok!
51 fn impl_fn_capture_hrtb_in_impl_trait<'b>()
52 -> Box<for<'a> Id<impl Lt<'b>>> // ok!