@@ -210,32 +210,38 @@ impl<T> Ptr<T> {
210210
211211 #[ inline]
212212 pub fn delete ( & self ) {
213- assert_eq ! ( self . offset, 0 , "ub: invalid delete" ) ;
214- let weak = match self . kind {
215- PtrKind :: HeapSingle ( ref weak) => weak,
213+ match & self . kind {
214+ PtrKind :: HeapSingle ( weak) => {
215+ assert_eq ! ( self . offset, 0 , "ub: invalid delete" ) ;
216+ assert_eq ! ( Weak :: strong_count( weak) , 1 , "ub: invalid delete" ) ;
217+ unsafe {
218+ let strong = weak. upgrade ( ) . expect ( "ub: dangling pointer" ) ;
219+ Rc :: from_raw ( Rc :: as_ptr ( & strong) ) ;
220+ }
221+ assert_eq ! ( Weak :: strong_count( weak) , 0 , "ub: double free" ) ;
222+ }
223+ PtrKind :: Reinterpreted ( data) => data. alloc . delete ( ) ,
224+ PtrKind :: Null => { }
216225 _ => panic ! ( "ub: invalid delete" ) ,
217- } ;
218- assert_eq ! ( Weak :: strong_count( weak) , 1 , "ub: invalid delete" ) ;
219- unsafe {
220- let strong = weak. upgrade ( ) . expect ( "ub: dangling pointer" ) ;
221- Rc :: from_raw ( Rc :: as_ptr ( & strong) ) ;
222226 }
223- assert_eq ! ( Weak :: strong_count( weak) , 0 , "ub: strong count is not zero" ) ;
224227 }
225228
226229 #[ inline]
227230 pub fn delete_array ( & self ) {
228- assert_eq ! ( self . offset, 0 , "ub: invalid delete" ) ;
229- let weak = match self . kind {
230- PtrKind :: HeapArray ( ref weak) => weak,
231+ match & self . kind {
232+ PtrKind :: HeapArray ( weak) => {
233+ assert_eq ! ( self . offset, 0 , "ub: invalid delete" ) ;
234+ assert_eq ! ( Weak :: strong_count( weak) , 1 , "ub: invalid delete" ) ;
235+ unsafe {
236+ let strong = weak. upgrade ( ) . expect ( "ub: dangling pointer" ) ;
237+ Rc :: from_raw ( Rc :: as_ptr ( & strong) ) ;
238+ }
239+ assert_eq ! ( Weak :: strong_count( weak) , 0 , "ub: double free" ) ;
240+ }
241+ PtrKind :: Reinterpreted ( data) => data. alloc . delete ( ) ,
242+ PtrKind :: Null => { }
231243 _ => panic ! ( "ub: invalid delete" ) ,
232- } ;
233- assert_eq ! ( Weak :: strong_count( weak) , 1 , "ub: invalid delete" ) ;
234- unsafe {
235- let strong = weak. upgrade ( ) . expect ( "ub: dangling pointer" ) ;
236- Rc :: from_raw ( Rc :: as_ptr ( & strong) ) ;
237244 }
238- assert_eq ! ( Weak :: strong_count( weak) , 0 , "ub: strong count is not zero" ) ;
239245 }
240246
241247 #[ inline]
0 commit comments