You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Just to confirm, this is still sound to call with types with a lifetime, e.g. if I make a function like:
fntype_equal<T1,T2>() -> bool{non_static_type_id::<T1>() == non_static_type_id::<T2>()}// this is fine:type_equal::<&'static str,u8>();type_equal::<u8,&'static str>();// this could result in unsoundness:// type_equal::<&'a str, &'b str>();
It is sound to get the TypeId for any T using this method. You only need to be concerned about the soundness of unsafe code that downcasts based on the value of the obtained TypeId, as different types can have the same TypeId. So non_static_type_id::<T>() == TypeId::of::<&'static str>() does not mean that you can downcast to &'static str.
I noticed this comment:
bincode/src/de/impls.rs
Lines 449 to 452 in a22afa3
You can implement the condition soundly as
non_static_type_id::<T>() == TypeId::of::<u8>()
where:This is sound because all types with the same TypeId as
u8
areu8
. In contrast, not all types with the same TypeId as&'static str
are&'static str
.The text was updated successfully, but these errors were encountered: