@@ -168,7 +168,9 @@ const fn in_place_collectible<DEST, SRC>(
168
168
step_merge : Option < NonZeroUsize > ,
169
169
step_expand : Option < NonZeroUsize > ,
170
170
) -> bool {
171
- if const { SRC :: IS_ZST || DEST :: IS_ZST || mem:: align_of :: < SRC > ( ) < mem:: align_of :: < DEST > ( ) } {
171
+ // Require matching alignments because an alignment-changing realloc is inefficient on many
172
+ // system allocators and better implementations would require the unstable Allocator trait.
173
+ if const { SRC :: IS_ZST || DEST :: IS_ZST || mem:: align_of :: < SRC > ( ) != mem:: align_of :: < DEST > ( ) } {
172
174
return false ;
173
175
}
174
176
@@ -188,7 +190,8 @@ const fn in_place_collectible<DEST, SRC>(
188
190
189
191
const fn needs_realloc < SRC , DEST > ( src_cap : usize , dst_cap : usize ) -> bool {
190
192
if const { mem:: align_of :: < SRC > ( ) != mem:: align_of :: < DEST > ( ) } {
191
- return src_cap > 0 ;
193
+ // FIXME: use unreachable! once that works in const
194
+ panic ! ( "in_place_collectible() prevents this" ) ;
192
195
}
193
196
194
197
// If src type size is an integer multiple of the destination type size then
@@ -276,8 +279,8 @@ where
276
279
let dst_guard = InPlaceDstBufDrop { ptr : dst_buf, len, cap : dst_cap } ;
277
280
src. forget_allocation_drop_remaining ( ) ;
278
281
279
- // Adjust the allocation if the alignment didn't match or the source had a capacity in bytes
280
- // that wasn't a multiple of the destination type size.
282
+ // Adjust the allocation if the source had a capacity in bytes that wasn't a multiple
283
+ // of the destination type size.
281
284
// Since the discrepancy should generally be small this should only result in some
282
285
// bookkeeping updates and no memmove.
283
286
if needs_realloc :: < I :: Src , T > ( src_cap, dst_cap) {
@@ -290,7 +293,7 @@ where
290
293
let src_size = mem:: size_of :: < I :: Src > ( ) . unchecked_mul ( src_cap) ;
291
294
let old_layout = Layout :: from_size_align_unchecked ( src_size, src_align) ;
292
295
293
- // The must be equal or smaller for in-place iteration to be possible
296
+ // The allocation must be equal or smaller for in-place iteration to be possible
294
297
// therefore the new layout must be ≤ the old one and therefore valid.
295
298
let dst_align = mem:: align_of :: < T > ( ) ;
296
299
let dst_size = mem:: size_of :: < T > ( ) . unchecked_mul ( dst_cap) ;
0 commit comments