about summary refs log tree commit diff
path: root/library/alloc/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2024-01-20 19:55:26 +0000
committerbors <bors@rust-lang.org>2024-01-20 19:55:26 +0000
commit038d115cd8659bbe4d5e9600839759f55dfcfb0c (patch)
tree38a3eb678d48946c490d1c31e7b1fd9ff819a8be /library/alloc/src
parent1828461982f37d1a0053d156cedad5522b0f8a97 (diff)
parent774cd3afd5dad311f9be97f74eb6d1a89ad06d38 (diff)
downloadrust-038d115cd8659bbe4d5e9600839759f55dfcfb0c.tar.gz
rust-038d115cd8659bbe4d5e9600839759f55dfcfb0c.zip
Auto merge of #120170 - GuillaumeGomez:rollup-edqdf30, r=GuillaumeGomez
Rollup of 6 pull requests

Successful merges:

 - #119997 (Fix impl stripped in rustdoc HTML whereas it should not be in case the impl is implemented on a type alias)
 - #120000 (Ensure `callee_id`s are body owners)
 - #120063 (Remove special handling of `box` expressions from parser)
 - #120116 (Remove alignment-changing in-place collect)
 - #120138 (Increase vscode settings.json `git.detectSubmodulesLimit`)
 - #120169 (Spelling fix)

r? `@ghost`
`@rustbot` modify labels: rollup
Diffstat (limited to 'library/alloc/src')
-rw-r--r--library/alloc/src/vec/in_place_collect.rs13
-rw-r--r--library/alloc/src/vec/spec_from_iter.rs14
2 files changed, 15 insertions, 12 deletions
diff --git a/library/alloc/src/vec/in_place_collect.rs b/library/alloc/src/vec/in_place_collect.rs
index ec5f32539f2..5a783e66752 100644
--- a/library/alloc/src/vec/in_place_collect.rs
+++ b/library/alloc/src/vec/in_place_collect.rs
@@ -168,7 +168,9 @@ const fn in_place_collectible<DEST, SRC>(
     step_merge: Option<NonZeroUsize>,
     step_expand: Option<NonZeroUsize>,
 ) -> bool {
-    if const { SRC::IS_ZST || DEST::IS_ZST || mem::align_of::<SRC>() < mem::align_of::<DEST>() } {
+    // Require matching alignments because an alignment-changing realloc is inefficient on many
+    // system allocators and better implementations would require the unstable Allocator trait.
+    if const { SRC::IS_ZST || DEST::IS_ZST || mem::align_of::<SRC>() != mem::align_of::<DEST>() } {
         return false;
     }
 
@@ -188,7 +190,8 @@ const fn in_place_collectible<DEST, SRC>(
 
 const fn needs_realloc<SRC, DEST>(src_cap: usize, dst_cap: usize) -> bool {
     if const { mem::align_of::<SRC>() != mem::align_of::<DEST>() } {
-        return src_cap > 0;
+        // FIXME: use unreachable! once that works in const
+        panic!("in_place_collectible() prevents this");
     }
 
     // If src type size is an integer multiple of the destination type size then
@@ -276,8 +279,8 @@ where
         let dst_guard = InPlaceDstBufDrop { ptr: dst_buf, len, cap: dst_cap };
         src.forget_allocation_drop_remaining();
 
-        // Adjust the allocation if the alignment didn't match or the source had a capacity in bytes
-        // that wasn't a multiple of the destination type size.
+        // Adjust the allocation if the source had a capacity in bytes that wasn't a multiple
+        // of the destination type size.
         // Since the discrepancy should generally be small this should only result in some
         // bookkeeping updates and no memmove.
         if needs_realloc::<I::Src, T>(src_cap, dst_cap) {
@@ -290,7 +293,7 @@ where
                 let src_size = mem::size_of::<I::Src>().unchecked_mul(src_cap);
                 let old_layout = Layout::from_size_align_unchecked(src_size, src_align);
 
-                // The must be equal or smaller for in-place iteration to be possible
+                // The allocation must be equal or smaller for in-place iteration to be possible
                 // therefore the new layout must be ≤ the old one and therefore valid.
                 let dst_align = mem::align_of::<T>();
                 let dst_size = mem::size_of::<T>().unchecked_mul(dst_cap);
diff --git a/library/alloc/src/vec/spec_from_iter.rs b/library/alloc/src/vec/spec_from_iter.rs
index e976552cf2b..33dd4139bc0 100644
--- a/library/alloc/src/vec/spec_from_iter.rs
+++ b/library/alloc/src/vec/spec_from_iter.rs
@@ -13,13 +13,13 @@ use super::{IntoIter, SpecExtend, SpecFromIterNested, Vec};
 /// +-+-----------+
 ///   |
 ///   v
-/// +-+-------------------------------+  +---------------------+
-/// |SpecFromIter                  +---->+SpecFromIterNested   |
-/// |where I:                      |  |  |where I:             |
-/// |  Iterator (default)----------+  |  |  Iterator (default) |
-/// |  vec::IntoIter               |  |  |  TrustedLen         |
-/// |  SourceIterMarker---fallback-+  |  +---------------------+
-/// +---------------------------------+
+/// +-+---------------------------------+  +---------------------+
+/// |SpecFromIter                    +---->+SpecFromIterNested   |
+/// |where I:                        |  |  |where I:             |
+/// |  Iterator (default)------------+  |  |  Iterator (default) |
+/// |  vec::IntoIter                 |  |  |  TrustedLen         |
+/// |  InPlaceCollect--(fallback to)-+  |  +---------------------+
+/// +-----------------------------------+
 /// ```
 pub(super) trait SpecFromIter<T, I> {
     fn from_iter(iter: I) -> Self;