File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -158,6 +158,9 @@ impl<T: 'static> ErasedPtr for FnPtr<T> {
158158 fn is_null ( & self ) -> bool {
159159 FnPtr :: is_null ( self )
160160 }
161+ fn is_dangling ( & self ) -> bool {
162+ false
163+ }
161164}
162165
163166impl < T : ' static > FnPtr < T > {
Original file line number Diff line number Diff line change @@ -1054,6 +1054,7 @@ pub(crate) trait ErasedPtr: std::any::Any {
10541054 fn as_any ( & self ) -> & dyn std:: any:: Any ;
10551055 fn equals ( & self , other : & dyn ErasedPtr ) -> bool ;
10561056 fn is_null ( & self ) -> bool ;
1057+ fn is_dangling ( & self ) -> bool ;
10571058}
10581059
10591060impl PartialEq for dyn ErasedPtr {
@@ -1085,6 +1086,16 @@ where
10851086 fn is_null ( & self ) -> bool {
10861087 Ptr :: is_null ( self )
10871088 }
1089+
1090+ fn is_dangling ( & self ) -> bool {
1091+ match & self . kind {
1092+ PtrKind :: Null => false ,
1093+ PtrKind :: StackSingle ( w) | PtrKind :: HeapSingle ( w) => w. strong_count ( ) == 0 ,
1094+ PtrKind :: Vec ( w) => w. strong_count ( ) == 0 ,
1095+ PtrKind :: StackArray ( w) | PtrKind :: HeapArray ( w) => w. strong_count ( ) == 0 ,
1096+ PtrKind :: Reinterpreted ( data) => data. alloc . is_dangling ( ) ,
1097+ }
1098+ }
10881099}
10891100
10901101#[ derive( Clone ) ]
Original file line number Diff line number Diff line change @@ -100,6 +100,7 @@ pub trait OriginalAlloc {
100100 fn total_byte_len ( & self ) -> usize ;
101101 // Stable address used for pointer equality across PtrKind variants.
102102 fn address ( & self ) -> usize ;
103+ fn is_dangling ( & self ) -> bool ;
103104}
104105
105106// Read bytes starting at `byte_offset` from a slice of S elements into `buf`.
@@ -165,6 +166,10 @@ impl<T: ByteRepr> OriginalAlloc for SingleOriginalAlloc<T> {
165166 fn address ( & self ) -> usize {
166167 self . weak . as_ptr ( ) as usize
167168 }
169+
170+ fn is_dangling ( & self ) -> bool {
171+ self . weak . strong_count ( ) == 0
172+ }
168173}
169174
170175pub ( crate ) trait AsSlice {
@@ -219,4 +224,8 @@ impl<T: AsSlice + 'static> OriginalAlloc for SliceOriginalAlloc<T> {
219224 fn address ( & self ) -> usize {
220225 self . weak . as_ptr ( ) as usize
221226 }
227+
228+ fn is_dangling ( & self ) -> bool {
229+ self . weak . strong_count ( ) == 0
230+ }
222231}
You can’t perform that action at this time.
0 commit comments