1 A lifetime didn't match what was expected.
3 Erroneous code example:
6 struct Foo<'a, 'b, T>(std::marker::PhantomData<(&'a (), &'b (), T)>)
10 trait Convert<'a, 'b>: Sized {
11 fn cast(&'a self) -> &'b Self;
13 impl<'long: 'short, 'short, T> Convert<'long, 'short> for T {
14 fn cast(&'long self) -> &'short T {
19 fn badboi<'in_, 'out, T>(
20 x: Foo<'in_, 'out, T>,
27 In this example, we tried to set a value with an incompatible lifetime to
28 another one (`'in_` is unrelated to `'out`). We can solve this issue in
31 Either we make `'in_` live at least as long as `'out`:
34 struct Foo<'a, 'b, T>(std::marker::PhantomData<(&'a (), &'b (), T)>)
38 trait Convert<'a, 'b>: Sized {
39 fn cast(&'a self) -> &'b Self;
41 impl<'long: 'short, 'short, T> Convert<'long, 'short> for T {
42 fn cast(&'long self) -> &'short T {
46 fn badboi<'in_: 'out, 'out, T>(
47 x: Foo<'in_, 'out, T>,
54 Or we use only one lifetime:
57 struct Foo<'a, 'b, T>(std::marker::PhantomData<(&'a (), &'b (), T)>)
61 trait Convert<'a, 'b>: Sized {
62 fn cast(&'a self) -> &'b Self;
64 impl<'long: 'short, 'short, T> Convert<'long, 'short> for T {
65 fn cast(&'long self) -> &'short T {
69 fn badboi<'out, T>(x: Foo<'out, 'out, T>, sadness: &'out T) -> &'out T {