@@ -521,6 +521,21 @@ impl<T> Ptr<T> {
521521 self . kind . address ( ) . wrapping_add ( self . byte_offset ( ) )
522522 }
523523
524+ // The address of the object that the pointer points to in the C++ layout
525+ // of its allocation, which reinterpreted views of the allocation share,
526+ // e.g., to compare pointers of different types as void*.
527+ pub ( crate ) fn byte_address ( & self ) -> usize
528+ where
529+ T : ByteRepr ,
530+ {
531+ let offset = match & self . kind {
532+ PtrKind :: Null => return 0 ,
533+ PtrKind :: Reinterpreted ( _) | PtrKind :: Field ( _, _, FieldShape :: Single ) => self . offset ,
534+ _ => self . offset . wrapping_mul ( T :: byte_size ( ) ) ,
535+ } ;
536+ self . kind . address ( ) . wrapping_add ( offset)
537+ }
538+
524539 // Normalize offset to bytes for cross-variant comparison.
525540 #[ inline]
526541 fn byte_offset ( & self ) -> usize {
@@ -1240,38 +1255,6 @@ impl<T: std::cmp::Ord + 'static> Ptr<T> {
12401255 }
12411256}
12421257
1243- impl < T > IntoIterator for & Ptr < T >
1244- where
1245- T : Clone ,
1246- {
1247- type Item = Ptr < T > ;
1248- type IntoIter = Ptr < T > ;
1249-
1250- fn into_iter ( self ) -> Self :: IntoIter {
1251- self . clone ( )
1252- }
1253- }
1254-
1255- impl < T > Iterator for Ptr < T > {
1256- type Item = Ptr < T > ;
1257- fn next ( & mut self ) -> Option < Self :: Item > {
1258- if self . get_offset ( ) < self . len ( ) {
1259- let value = self . clone ( ) ;
1260- self . offset += self . elem_step ( ) ;
1261- Some ( value)
1262- } else {
1263- None
1264- }
1265- }
1266-
1267- // Lets collections built from the iterator (e.g. `std::string`'s
1268- // constructors) allocate their storage once instead of growing it.
1269- fn size_hint ( & self ) -> ( usize , Option < usize > ) {
1270- let remaining = self . len ( ) . saturating_sub ( self . get_offset ( ) ) ;
1271- ( remaining, Some ( remaining) )
1272- }
1273- }
1274-
12751258impl < T > Sub for Ptr < T > {
12761259 type Output = isize ;
12771260 fn sub ( self , other : Self ) -> Self :: Output {
@@ -1428,13 +1411,6 @@ impl<T> AsPointer<T> for Option<Rc<RefCell<Box<[T]>>>> {
14281411 }
14291412}
14301413
1431- impl < T > AsPointer < Vec < T > > for Ptr < Vec < T > > {
1432- #[ inline]
1433- fn as_pointer ( & self ) -> Ptr < Vec < T > > {
1434- self . clone ( )
1435- }
1436- }
1437-
14381414impl < T : ' static > Ptr < Vec < T > > {
14391415 #[ inline]
14401416 pub fn decay ( & self ) -> Ptr < T > {
@@ -1467,20 +1443,6 @@ impl<T: 'static> Ptr<Vec<T>> {
14671443 }
14681444}
14691445
1470- impl < T > AsPointer < Box < [ T ] > > for Ptr < Box < [ T ] > > {
1471- #[ inline]
1472- fn as_pointer ( & self ) -> Ptr < Box < [ T ] > > {
1473- self . clone ( )
1474- }
1475- }
1476-
1477- impl < T : ' static > AsPointer < T > for Ptr < Box < [ T ] > > {
1478- #[ inline]
1479- fn as_pointer ( & self ) -> Ptr < T > {
1480- self . decay ( )
1481- }
1482- }
1483-
14841446impl < T : ' static > Ptr < Box < [ T ] > > {
14851447 #[ inline]
14861448 pub fn decay ( & self ) -> Ptr < T > {
0 commit comments