@@ -225,16 +225,18 @@ where
225
225
}
226
226
227
227
// The ownership of the allocation and the new `T` values is temporarily moved into `dst_guard`.
228
- // This is safe because `forget_allocation_drop_remaining` immediately forgets the allocation
228
+ // This is safe because
229
+ // * `forget_allocation_drop_remaining` immediately forgets the allocation
229
230
// before any panic can occur in order to avoid any double free, and then proceeds to drop
230
231
// any remaining values at the tail of the source.
232
+ // * the shrink either panics without invalidating the allocation, aborts or
233
+ // succeeds. In the last case we disarm the guard.
231
234
//
232
235
// Note: This access to the source wouldn't be allowed by the TrustedRandomIteratorNoCoerce
233
236
// contract (used by SpecInPlaceCollect below). But see the "O(1) collect" section in the
234
237
// module documentation why this is ok anyway.
235
238
let dst_guard = InPlaceDstBufDrop { ptr : dst_buf, len, cap : dst_cap } ;
236
239
src. forget_allocation_drop_remaining ( ) ;
237
- mem:: forget ( dst_guard) ;
238
240
239
241
// Adjust the allocation size if the source had a capacity in bytes that wasn't a multiple
240
242
// of the destination type size.
@@ -256,6 +258,8 @@ where
256
258
}
257
259
}
258
260
261
+ mem:: forget ( dst_guard) ;
262
+
259
263
let vec = unsafe { Vec :: from_raw_parts ( dst_buf, len, dst_cap) } ;
260
264
261
265
vec
0 commit comments