Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 4841e83

Browse files
authoredMar 17, 2025
Unrolled build for rust-lang#136293
Rollup merge of rust-lang#136293 - hkBst:patch-32, r=Amanieu document capacity for ZST as example The main text already covers this, although it provides weaker guarantees, but I think an example in the right spot does not hurt. Fixes rust-lang#80747
2 parents c3dd4ee + db7e61c commit 4841e83

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed
 

‎library/alloc/src/vec/mod.rs

+13
Original file line numberDiff line numberDiff line change
@@ -1252,6 +1252,19 @@ impl<T, A: Allocator> Vec<T, A> {
12521252
/// vec.push(42);
12531253
/// assert!(vec.capacity() >= 10);
12541254
/// ```
1255+
///
1256+
/// A vector with zero-sized elements will always have a capacity of usize::MAX:
1257+
///
1258+
/// ```
1259+
/// #[derive(Clone)]
1260+
/// struct ZeroSized;
1261+
///
1262+
/// fn main() {
1263+
/// assert_eq!(std::mem::size_of::<ZeroSized>(), 0);
1264+
/// let v = vec![ZeroSized; 0];
1265+
/// assert_eq!(v.capacity(), usize::MAX);
1266+
/// }
1267+
/// ```
12551268
#[inline]
12561269
#[stable(feature = "rust1", since = "1.0.0")]
12571270
#[rustc_const_stable(feature = "const_vec_string_slice", since = "CURRENT_RUSTC_VERSION")]

0 commit comments

Comments
 (0)
Failed to load comments.