Closed
Description
As far as I can tell, from the point of view of lifetimes, PhantomData<T>
should behave identically to T
. This is unfortunately not the case in practice.
This function causes a mismatched type error on x
:
fn cast_phantom<'a, 'b, T>(x: PhantomData<&'a T>) -> PhantomData<&'b T> where 'a : 'b {
x
}
Whereas this similar function does not:
fn cast_actual<'a, 'b, T>(x: &'a T) -> &'b T where 'a : 'b {
x
}
The variance rules of lifetimes should make both functions valid.
Metadata
Metadata
Assignees
Labels
No labels