Skip to content

Commit f8f606f

Browse files
committed
Auto merge of #151389 - scottmcm:vec-repeat, r=joboet
Use `repeat_packed` when calculating layouts in `RawVec` Seeing whether this helps the icounts seen in #148769 (comment)
2 parents 88ad3d4 + 73a43c5 commit f8f606f

File tree

1 file changed

+6
-2
lines changed
  • library/alloc/src/raw_vec

1 file changed

+6
-2
lines changed

library/alloc/src/raw_vec/mod.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -865,9 +865,13 @@ const fn handle_error(e: TryReserveError) -> ! {
865865
#[inline]
866866
#[rustc_const_unstable(feature = "const_heap", issue = "79597")]
867867
const fn layout_array(cap: usize, elem_layout: Layout) -> Result<Layout, TryReserveError> {
868+
// This is only used with `elem_layout`s which are those of real rust types,
869+
// which lets us use the much-simpler `repeat_packed`.
870+
debug_assert!(elem_layout.size() == elem_layout.pad_to_align().size());
871+
868872
// FIXME(const-hack) return to using `map` and `map_err` once `const_closures` is implemented
869-
match elem_layout.repeat(cap) {
870-
Ok((layout, _pad)) => Ok(layout),
873+
match elem_layout.repeat_packed(cap) {
874+
Ok(layout) => Ok(layout),
871875
Err(_) => Err(CapacityOverflow.into()),
872876
}
873877
}

0 commit comments

Comments
 (0)