|
| 1 | +error: lifetime may not live long enough |
| 2 | + --> $DIR/flow-sensitive-invariance.rs:20:17 |
| 3 | + | |
| 4 | +LL | fn use_it<'a, 'b>(choice: bool) -> Result<Invariant<'a>, Invariant<'b>> { |
| 5 | + | -- -- lifetime `'b` defined here |
| 6 | + | | |
| 7 | + | lifetime `'a` defined here |
| 8 | +LL | let returned_value = create_invariant(); |
| 9 | +LL | if choice { Ok(returned_value) } else { Err(returned_value) } |
| 10 | + | ^^^^^^^^^^^^^^^^^^ function was supposed to return data with lifetime `'a` but it is returning data with lifetime `'b` |
| 11 | + | |
| 12 | + = help: consider adding the following bound: `'b: 'a` |
| 13 | + = note: requirement occurs because of the type `Invariant<'_>`, which makes the generic argument `'_` invariant |
| 14 | + = note: the struct `Invariant<'l>` is invariant over the parameter `'l` |
| 15 | + = help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance |
| 16 | + |
| 17 | +error: lifetime may not live long enough |
| 18 | + --> $DIR/flow-sensitive-invariance.rs:20:45 |
| 19 | + | |
| 20 | +LL | fn use_it<'a, 'b>(choice: bool) -> Result<Invariant<'a>, Invariant<'b>> { |
| 21 | + | -- -- lifetime `'b` defined here |
| 22 | + | | |
| 23 | + | lifetime `'a` defined here |
| 24 | +LL | let returned_value = create_invariant(); |
| 25 | +LL | if choice { Ok(returned_value) } else { Err(returned_value) } |
| 26 | + | ^^^^^^^^^^^^^^^^^^^ function was supposed to return data with lifetime `'b` but it is returning data with lifetime `'a` |
| 27 | + | |
| 28 | + = help: consider adding the following bound: `'a: 'b` |
| 29 | + = note: requirement occurs because of the type `Invariant<'_>`, which makes the generic argument `'_` invariant |
| 30 | + = note: the struct `Invariant<'l>` is invariant over the parameter `'l` |
| 31 | + = help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance |
| 32 | + |
| 33 | +help: `'a` and `'b` must be the same: replace one with the other |
| 34 | + |
| 35 | +error: aborting due to 2 previous errors |
| 36 | + |
0 commit comments