-
-
Notifications
You must be signed in to change notification settings - Fork 14.8k
PhantomData not behaving as advertised #22579
Copy link
Copy link
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.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
Type
Fields
Give feedbackNo fields configured for issues without a type.