@@ -1105,6 +1105,27 @@ pub const STRUCT_VARIANT_ID: i128 = -1;
11051105#[ doc( hidden) ]
11061106pub const UNION_VARIANT_ID : i128 = -2 ;
11071107
1108+ /// # Safety
1109+ ///
1110+ /// `Self::ProjectToTag` must satisfy its safety invariant.
1111+ #[ doc( hidden) ]
1112+ pub unsafe trait HasTag {
1113+ fn only_derive_is_allowed_to_implement_this_trait ( )
1114+ where
1115+ Self : Sized ;
1116+
1117+ /// The type's enum tag, or `()` for non-enum types.
1118+ type Tag : Immutable ;
1119+
1120+ /// A pointer projection from `Self` to its tag.
1121+ ///
1122+ /// # Safety
1123+ ///
1124+ /// It must be the case that, for all `slf: Ptr<'_, Self, I>`, it is sound
1125+ /// to project from `slf` to `Ptr<'_, Self::Tag, I>` using this projection.
1126+ type ProjectToTag : pointer:: cast:: Project < Self , Self :: Tag > ;
1127+ }
1128+
11081129/// Projects a given field from `Self`.
11091130///
11101131/// All implementations of `HasField` for a particular field `f` in `Self`
@@ -1131,7 +1152,9 @@ pub const UNION_VARIANT_ID: i128 = -2;
11311152///
11321153/// The implementation of `project` must satisfy its safety post-condition.
11331154#[ doc( hidden) ]
1134- pub unsafe trait HasField < Field , const VARIANT_ID : i128 , const FIELD_ID : i128 > {
1155+ pub unsafe trait HasField < Field , const VARIANT_ID : i128 , const FIELD_ID : i128 > :
1156+ HasTag
1157+ {
11351158 fn only_derive_is_allowed_to_implement_this_trait ( )
11361159 where
11371160 Self : Sized ;
@@ -1163,7 +1186,7 @@ pub unsafe trait HasField<Field, const VARIANT_ID: i128, const FIELD_ID: i128> {
11631186/// # Safety
11641187///
11651188/// `T: ProjectField<Field, I, VARIANT_ID, FIELD_ID>` if, for a
1166- /// `slf : Ptr<'_, T, I>` such that `if let Ok(ptr) = T::is_projectable(slf )`,
1189+ /// `ptr : Ptr<'_, T, I>` such that `T::is_projectable(ptr).is_ok( )`,
11671190/// `<T as HasField<Field, VARIANT_ID, FIELD_ID>>::project(ptr.as_inner())`
11681191/// conforms to `T::Invariants`.
11691192#[ doc( hidden) ]
@@ -1194,7 +1217,7 @@ where
11941217 /// This method must be overriden if the field's projectability depends on
11951218 /// the value of the bytes in `ptr`.
11961219 #[ inline( always) ]
1197- fn is_projectable < ' a > ( ptr : Ptr < ' a , Self , I > ) -> Result < Ptr < ' a , Self , I > , Self :: Error > {
1220+ fn is_projectable < ' a > ( _ptr : Ptr < ' a , Self :: Tag , I > ) -> Result < ( ) , Self :: Error > {
11981221 trait IsInfallible {
11991222 const IS_INFALLIBLE : bool ;
12001223 }
@@ -1248,7 +1271,7 @@ where
12481271 <Projection <Self , Field , I , VARIANT_ID , FIELD_ID > as IsInfallible >:: IS_INFALLIBLE
12491272 ) ;
12501273
1251- Ok ( ptr )
1274+ Ok ( ( ) )
12521275 }
12531276}
12541277
0 commit comments