Closed as not planned
Description
I tried this code:
trait Trait<'a> {}
fn convert<'short, 'long: 'short>(
obj: Box<dyn Trait<'short> + 'long>,
) -> Box<dyn Trait<'long> + 'long> {
obj
}
I expected to see this happen: It compiles. The concrete type of the dyn Trait<'short> + 'long
cannot mention 'short
(as it lives for all of 'long
), so it must implement Trait<'long>
also.
Instead, this happened:
error: lifetime may not live long enough
--> src/lib.rs:6:5
|
3 | fn convert<'short, 'long: 'short>(
| ------ ----- lifetime `'long` defined here
| |
| lifetime `'short` defined here
...
6 | obj
| ^^^ function was supposed to return data with lifetime `'long` but it is returning data with lifetime `'short`
|
= help: consider adding the following bound: `'short: 'long`
Meta
rustc --version
:
1.86.0
@rustbot label A-lifetimes A-trait-objects T-types