Skip to content

Update subtree/library to 2025-04-19 #23

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 131 commits into
base: subtree/library
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
131 commits
Select commit Hold shift + click to select a range
37e5a37
Use `BinOp::Cmp` for `iNN::signum`
scottmcm Mar 1, 2025
a0366cf
mark cfg_match! semitransparent
CAD97 Mar 26, 2025
52c577b
Expose `Unique::from<NonNull>` in const internally
jwnrt Mar 26, 2025
992ce7e
Pass `Alignment` for `RawVecInner::new_in`
jwnrt Mar 25, 2025
e0f3eb4
Swap usize -> ptr transmute for strict_pov API
jwnrt Mar 25, 2025
cf5b8ff
Promise `array::from_fn` in generated in order of increasing indices
scottmcm Mar 29, 2025
d774629
std: make `cmath` functions safe
joboet Mar 29, 2025
c09288c
std: clarify Mutex::get_mut more clearly
xizheyin Mar 31, 2025
86f5fa2
Revert "Disable `f16` on Aarch64 without `neon`"
tgross35 Apr 2, 2025
3c1bc2d
std: clarify RefCell::get_mut more clearly
xizheyin Mar 31, 2025
382f937
std: clarify RwLock::get_mut more clearly
xizheyin Mar 31, 2025
49287f3
Update windows-bindgen to 0.61.0
ChrisDenton Apr 4, 2025
3ac6a89
std: Fix build for NuttX targets
thaliaarchi Mar 26, 2025
849596c
Polymorphize `array::IntoIter`'s iterator impl
scottmcm Apr 6, 2025
71a55a4
doc changes
doodooboy-bit Apr 6, 2025
96ef343
update docs
Skgland Apr 6, 2025
83ed8e3
Auto merge of #138951 - jwnrt:alloc-raw-vec-strict-prov, r=Noratrieb
bors Apr 6, 2025
12c4e7d
Rollup merge of #139455 - Skgland:remove_rust-intrinsic_ABI, r=oli-obk
Zalathar Apr 7, 2025
32cc982
f*::NAN: guarantee that this is a quiet NaN
RalfJung Apr 7, 2025
efe414a
update intrinsics/mod.rs comment about const intrinsics
RalfJung Apr 7, 2025
d96e3e7
Enable contracts for const functions
celinval Feb 25, 2025
462105c
document panic behavior of Vec::resize and Vec::resize_with
jogru0 Apr 7, 2025
195ff5b
libtest: Pass the test's panic payload as Option instead of Result
Zalathar Apr 8, 2025
7085885
Fix deprecation note for std::intrinsics
smanilov Apr 8, 2025
a972589
Update 'u8'-to-and-from-'i8' suggestions;
bjoernager Apr 8, 2025
910a867
Rollup merge of #139500 - jogru0:117437, r=tgross35
matthiaskrgr Apr 8, 2025
c5a4094
Fix unreachable expression warning
celinval Apr 8, 2025
ff64fc4
Rollup merge of #139526 - smanilov:issue-139505, r=RalfJung
matthiaskrgr Apr 8, 2025
c7222e8
Avoid verbatim paths in Command::current_dir
ChrisDenton Mar 24, 2025
5e74776
Auto merge of #139552 - matthiaskrgr:rollup-b194mk8, r=matthiaskrgr
bors Apr 9, 2025
ad3dc4a
Speed up `String::push` and `String::insert`
lincot May 6, 2024
ea11540
Add missing `black_box` in `String` benchmarks
lincot Apr 8, 2025
b61acfb
Remove redundant words
timesince Apr 9, 2025
1575738
replace version placeholder
BoxyUwU Mar 31, 2025
7dd1036
update cfgs
BoxyUwU Apr 2, 2025
e552ad6
intra-doc link
BoxyUwU Apr 3, 2025
5b5b1e2
Rollup merge of #138869 - ChrisDenton:command-curdir, r=tgross35
matthiaskrgr Apr 9, 2025
a3b67d3
Rollup merge of #138993 - CAD97:cfg_match_semitransparent, r=dtolnay
matthiaskrgr Apr 9, 2025
d904053
Rollup merge of #139099 - scottmcm:from_fn_docs, r=Amanieu
matthiaskrgr Apr 9, 2025
06dee73
Ensure `swap_nonoverlapping` is really always untyped
scottmcm Feb 22, 2025
b672b1d
Auto merge of #124810 - lincot:speed-up-string-push-and-string-insert…
bors Apr 9, 2025
39987b9
Rollup merge of #139164 - xizheyin:issue-139034, r=joboet
matthiaskrgr Apr 9, 2025
c96ea2a
Rollup merge of #139532 - bjoernager:master, r=tgross35
matthiaskrgr Apr 9, 2025
a7ba49a
Rollup merge of #139575 - timesince:master, r=wesleywiser
matthiaskrgr Apr 9, 2025
1e4dce6
Auto merge of #139595 - matthiaskrgr:rollup-kaa8aim, r=matthiaskrgr
bors Apr 9, 2025
fe6b3f4
update miniz_oxide to 0.8.8
oyvindln Apr 9, 2025
9054e9d
Auto merge of #139279 - BoxyUwU:bump-boostrap, r=jieyouxu
bors Apr 10, 2025
8df3f93
PR feedback
scottmcm Apr 9, 2025
3fae1c3
cfi: do not transmute function pointers in formatting code
Darksonn Apr 10, 2025
315f182
Update `compiler-builtins` to 0.1.153
tgross35 Apr 9, 2025
e017596
add `simd_insert_dyn` and `simd_extract_dyn`
folkertdev Feb 22, 2025
df8d99a
Auto merge of #137412 - scottmcm:redo-swap, r=cuviper
bors Apr 10, 2025
0d4f906
Apply suggestions from code review
celinval Apr 10, 2025
4e136a0
indirect-const-stabilize the `exact_div` intrinsic
scottmcm Mar 31, 2025
51e9b40
Rollup merge of #137447 - folkertdev:simd-extract-insert-dyn, r=scottmcm
Zalathar Apr 11, 2025
f9a32ef
Rollup merge of #139447 - izarma:issue-108131-fix, r=scottmcm
Zalathar Apr 11, 2025
b337b15
Rollup merge of #139600 - tgross35:update-builtins, r=tgross35
Zalathar Apr 11, 2025
71b3d68
cfi: Remove #[no_sanitize(cfi)] for extern weak functions
1c3t3a Apr 11, 2025
485eff7
Remove proc_macro::SourceFile::is_real().
m-ou-se Apr 11, 2025
17c68d1
sync::mpsc: add miri reproducer of double free
petrosagg Apr 10, 2025
5b1acd9
sync::mpsc: prevent double free on `Drop`
petrosagg Apr 8, 2025
2c3a474
Replace proc_macro::SourceFile by Span::{file, local_file}.
m-ou-se Apr 11, 2025
37170a5
Fix profiler_builtins build script to handle full path to profiler lib
Apr 11, 2025
7b95216
Update library/core/src/fmt/rt.rs
Darksonn Apr 11, 2025
278f039
Use with_native_path for Windows
ChrisDenton Apr 11, 2025
b40d106
rustdoc-search: add unbox flag to Result aliases
notriddle Apr 11, 2025
5762b35
Rollup merge of #137835 - scottmcm:signum, r=compiler-errors
jhpratt Apr 11, 2025
d1d4180
Auto merge of #139430 - scottmcm:polymorphic-array-into-iter, r=cuviper
bors Apr 11, 2025
26f2e18
docs: clarify uint exponent for `is_power_of_two`
Rudxain Apr 12, 2025
d3f21b6
Move args into std::sys
thaliaarchi Apr 12, 2025
8aa438a
cfg(kcfi)
Darksonn Apr 12, 2025
c5fd627
Use unsupported args for espidf and vita
thaliaarchi Apr 12, 2025
43b6c47
Unify owned Args types between platforms
thaliaarchi Apr 12, 2025
25aed7f
Fix typo in documentation
GenYuLi Apr 12, 2025
cc74b34
Rollup merge of #139163 - scottmcm:stabilize-exact_div, r=RalfJung
ChrisDenton Apr 12, 2025
f1124a0
Rollup merge of #139276 - tgross35:enable-f16-without-neon, r=Mark-Si…
ChrisDenton Apr 12, 2025
cd3a125
Rollup merge of #139382 - ChrisDenton:windows-bindgen-0-61, r=Mark-Si…
ChrisDenton Apr 12, 2025
2b92d8d
Rollup merge of #139688 - rust-lang:notriddle/io-result-unbox, r=Guil…
ChrisDenton Apr 12, 2025
4f06d6d
Rollup merge of #139701 - Rudxain:doc-pow2, r=tgross35
ChrisDenton Apr 12, 2025
5497097
Rollup merge of #139713 - GenYuLi:master, r=compiler-errors
ChrisDenton Apr 12, 2025
04029ed
Move `select_unpredictable` to the `hint` module
Amanieu Apr 12, 2025
5c9d14a
Rollup merge of #139107 - joboet:safe_cmath, r=ibraheemdev
ChrisDenton Apr 13, 2025
4af2452
Extend the chaining logic to slices too
scottmcm Mar 24, 2025
3b9a4b0
Initial `UnsafePinned`/`UnsafeUnpin` impl [Part 1: Libs]
Sky9x Feb 14, 2025
3df6b18
Auto merge of #139734 - ChrisDenton:rollup-28qn740, r=ChrisDenton
bors Apr 13, 2025
cd098f7
Auto merge of #138881 - scottmcm:more-chaining-ord, r=Mark-Simulacrum
bors Apr 13, 2025
320f165
Rollup merge of #138972 - thaliaarchi:nuttx-build, r=Mark-Simulacrum
ChrisDenton Apr 13, 2025
f6ee8a2
Rollup merge of #139511 - Zalathar:panic-payload, r=Mark-Simulacrum
ChrisDenton Apr 13, 2025
087649b
Rollup merge of #139605 - oyvindln:update_miniz_oxide_0_8, r=Mark-Sim…
ChrisDenton Apr 13, 2025
ed9ccd0
Rollup merge of #139677 - jchecahi:profiler-builtin-rtlib-path-fix, r…
ChrisDenton Apr 13, 2025
2cbb559
Rollup merge of #139683 - ChrisDenton:windows-with-native, r=tgross35…
ChrisDenton Apr 13, 2025
50f5112
Rollup merge of #139710 - thaliaarchi:move-args-pal, r=joboet
ChrisDenton Apr 13, 2025
ef96788
Rollup merge of #139726 - Amanieu:select_unpredictable_hint, r=dtolnay
ChrisDenton Apr 13, 2025
ec60cd5
std/thread: Use default stack size from menuconfig for NuttX
no1wudi Apr 13, 2025
d84a83b
Auto merge of #139746 - ChrisDenton:rollup-eq08b2e, r=ChrisDenton
bors Apr 13, 2025
b7ac487
std: sys: process: uefi: Use NULL stdin by default
Ayush1325 Apr 8, 2025
3f3732a
std: sys: stdio: uefi: Tread UNSUPPORTED Status as read(0)
Ayush1325 Apr 13, 2025
27bed75
std: sys: process: uefi: Allow specifying Stdin
Ayush1325 Apr 10, 2025
0e2c537
Rollup merge of #137043 - Sky9x:unsafe-pinned-pt1-libs, r=tgross35,Ra…
jhpratt Apr 13, 2025
2554815
Avoid unused clones in Cloned<I> and Copied<I>
thaliaarchi Apr 13, 2025
fb95ebb
Report span of test when should_panic test failed
xizheyin Mar 17, 2025
aa425a8
ptr docs: add missing backtics around 'usize'
RalfJung Apr 14, 2025
543820f
Auto merge of #138603 - xizheyin:issue-137405, r=chenyukang
bors Apr 14, 2025
5db3c5f
Auto merge of #139814 - matthiaskrgr:rollup-lxkkcz6, r=matthiaskrgr
bors Apr 14, 2025
7ace926
Fix: Map EOPNOTSUPP to ErrorKind::Unsupported on Unix
0x79de Apr 14, 2025
62e50de
Rollup merge of #139745 - thaliaarchi:iter-unused-clone-copy, r=joboet
matthiaskrgr Apr 14, 2025
2bca634
std: add Output::exit_ok
lolbinarycat Apr 8, 2025
8ff0ee1
Basic tests of MPMC receiver cloning
glyn Apr 15, 2025
caa9632
Rollup merge of #138374 - celinval:issue-136925-const-contract, r=com…
Zalathar Apr 15, 2025
e458986
Rollup merge of #139517 - Ayush1325:uefi-cmd-stdin-null, r=joboet
Zalathar Apr 15, 2025
39e05bf
Rollup merge of #139554 - lolbinarycat:std-output-exit_ok, r=tgross35
Zalathar Apr 15, 2025
f162c7f
Rollup merge of #139671 - m-ou-se:proc-macro-span, r=dtolnay
Zalathar Apr 15, 2025
504f564
Rollup merge of #139750 - no1wudi:fix, r=tgross35
Zalathar Apr 15, 2025
887af61
Rollup merge of #139822 - 0x79de:fix-eopnotsupp-mapping, r=dtolnay
Zalathar Apr 15, 2025
a40f2d0
Rollup merge of #139836 - glyn:test-mpmc-receiver-cloning, r=jhpratt
Zalathar Apr 15, 2025
143021c
Remove #![feature(no_sanitize)]
tamird Apr 14, 2025
18b4143
Use full path for core::mem::transmute
Darksonn Apr 14, 2025
829afa8
Add comment
Darksonn Apr 14, 2025
885f27c
Auto merge of #139845 - Zalathar:rollup-u5u5y1v, r=Zalathar
bors Apr 15, 2025
8c88f85
Auto merge of #139632 - Darksonn:cfi-fmt, r=m-ou-se
bors Apr 15, 2025
3429b5f
Add warning comment to `Take::get_ref` and `Chain::get_ref`
joshtriplett Apr 15, 2025
26513b9
Also remove the no_sanitize feature for std
1c3t3a Apr 15, 2025
5d82f7a
Update stdarch submodule
GuillaumeGomez Apr 16, 2025
9a520f8
Rollup merge of #139667 - 1c3t3a:remove-no-sanitize, r=m-ou-se
matthiaskrgr Apr 16, 2025
ed7cbf2
Fix drop handling in `hint::select_unpredictable`
Amanieu Apr 17, 2025
220a2e5
Update `compiler-builtins` to 0.1.155
tgross35 Apr 16, 2025
9267d04
Rollup merge of #139483 - RalfJung:nan, r=tgross35
matthiaskrgr Apr 17, 2025
1b2ff29
Rollup merge of #139977 - Amanieu:select_unpredictable_drop, r=RalfJung
matthiaskrgr Apr 17, 2025
ee51ea6
Rollup merge of #139553 - petrosagg:channel-double-free, r=RalfJung,t…
matthiaskrgr Apr 18, 2025
4b57af8
Rollup merge of #139934 - tgross35:update-builtins, r=tgross35
matthiaskrgr Apr 18, 2025
efaf4e0
Auto merge of #139996 - matthiaskrgr:rollup-0nka2hw, r=matthiaskrgr
bors Apr 18, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion alloc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ bench = false

[dependencies]
core = { path = "../core", public = true }
compiler_builtins = { version = "=0.1.152", features = ['rustc-dep-of-std'] }
compiler_builtins = { version = "=0.1.155", features = ['rustc-dep-of-std'] }

[features]
compiler-builtins-mem = ['compiler_builtins/mem']
Expand Down
14 changes: 7 additions & 7 deletions alloc/src/alloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,22 @@ unsafe extern "Rust" {
// otherwise.
#[rustc_allocator]
#[rustc_nounwind]
#[cfg_attr(not(bootstrap), rustc_std_internal_symbol)]
#[rustc_std_internal_symbol]
fn __rust_alloc(size: usize, align: usize) -> *mut u8;
#[rustc_deallocator]
#[rustc_nounwind]
#[cfg_attr(not(bootstrap), rustc_std_internal_symbol)]
#[rustc_std_internal_symbol]
fn __rust_dealloc(ptr: *mut u8, size: usize, align: usize);
#[rustc_reallocator]
#[rustc_nounwind]
#[cfg_attr(not(bootstrap), rustc_std_internal_symbol)]
#[rustc_std_internal_symbol]
fn __rust_realloc(ptr: *mut u8, old_size: usize, align: usize, new_size: usize) -> *mut u8;
#[rustc_allocator_zeroed]
#[rustc_nounwind]
#[cfg_attr(not(bootstrap), rustc_std_internal_symbol)]
#[rustc_std_internal_symbol]
fn __rust_alloc_zeroed(size: usize, align: usize) -> *mut u8;

#[cfg_attr(not(bootstrap), rustc_std_internal_symbol)]
#[rustc_std_internal_symbol]
static __rust_no_alloc_shim_is_unstable: u8;
}

Expand Down Expand Up @@ -360,7 +360,7 @@ unsafe extern "Rust" {
// This is the magic symbol to call the global alloc error handler. rustc generates
// it to call `__rg_oom` if there is a `#[alloc_error_handler]`, or to call the
// default implementations below (`__rdl_oom`) otherwise.
#[cfg_attr(not(bootstrap), rustc_std_internal_symbol)]
#[rustc_std_internal_symbol]
fn __rust_alloc_error_handler(size: usize, align: usize) -> !;
}

Expand Down Expand Up @@ -427,7 +427,7 @@ pub mod __alloc_error_handler {
unsafe extern "Rust" {
// This symbol is emitted by rustc next to __rust_alloc_error_handler.
// Its value depends on the -Zoom={panic,abort} compiler option.
#[cfg_attr(not(bootstrap), rustc_std_internal_symbol)]
#[rustc_std_internal_symbol]
static __rust_alloc_error_handler_should_panic: u8;
}

Expand Down
2 changes: 1 addition & 1 deletion alloc/src/boxed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -952,7 +952,7 @@ impl<T, A: Allocator> Box<mem::MaybeUninit<T>, A> {
/// assert_eq!(*x, i);
/// }
/// ```
#[stable(feature = "box_uninit_write", since = "CURRENT_RUSTC_VERSION")]
#[stable(feature = "box_uninit_write", since = "1.87.0")]
#[inline]
pub fn write(mut boxed: Self, value: T) -> Box<T, A> {
unsafe {
Expand Down
2 changes: 1 addition & 1 deletion alloc/src/collections/btree/set_val.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub(super) struct SetValZST;
/// Returns `true` only for type `SetValZST`, `false` for all other types (blanket implementation).
/// `TypeId` requires a `'static` lifetime, use of this trait avoids that restriction.
///
/// [`TypeId`]: std::any::TypeId
/// [`TypeId`]: core::any::TypeId
pub(super) trait IsSetVal {
fn is_set_val() -> bool;
}
Expand Down
8 changes: 4 additions & 4 deletions alloc/src/collections/linked_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1151,7 +1151,7 @@ impl<T, A: Allocator> LinkedList<T, A> {
/// assert_eq!(evens.into_iter().collect::<Vec<_>>(), vec![2, 4, 6, 8, 14]);
/// assert_eq!(odds.into_iter().collect::<Vec<_>>(), vec![1, 3, 5, 9, 11, 13, 15]);
/// ```
#[stable(feature = "extract_if", since = "CURRENT_RUSTC_VERSION")]
#[stable(feature = "extract_if", since = "1.87.0")]
pub fn extract_if<F>(&mut self, filter: F) -> ExtractIf<'_, T, F, A>
where
F: FnMut(&mut T) -> bool,
Expand Down Expand Up @@ -1931,7 +1931,7 @@ impl<'a, T, A: Allocator> CursorMut<'a, T, A> {
}

/// An iterator produced by calling `extract_if` on LinkedList.
#[stable(feature = "extract_if", since = "CURRENT_RUSTC_VERSION")]
#[stable(feature = "extract_if", since = "1.87.0")]
#[must_use = "iterators are lazy and do nothing unless consumed"]
pub struct ExtractIf<
'a,
Expand All @@ -1946,7 +1946,7 @@ pub struct ExtractIf<
old_len: usize,
}

#[stable(feature = "extract_if", since = "CURRENT_RUSTC_VERSION")]
#[stable(feature = "extract_if", since = "1.87.0")]
impl<T, F, A: Allocator> Iterator for ExtractIf<'_, T, F, A>
where
F: FnMut(&mut T) -> bool,
Expand Down Expand Up @@ -1975,7 +1975,7 @@ where
}
}

#[stable(feature = "extract_if", since = "CURRENT_RUSTC_VERSION")]
#[stable(feature = "extract_if", since = "1.87.0")]
impl<T: fmt::Debug, F> fmt::Debug for ExtractIf<'_, T, F> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_tuple("ExtractIf").field(&self.list).finish()
Expand Down
2 changes: 1 addition & 1 deletion alloc/src/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
//! parameters (corresponding to `format_spec` in [the syntax](#syntax)). These
//! parameters affect the string representation of what's being formatted.
//!
//! The colon `:` in format syntax divides indentifier of the input data and
//! The colon `:` in format syntax divides identifier of the input data and
//! the formatting options, the colon itself does not change anything, only
//! introduces the options.
//!
Expand Down
2 changes: 2 additions & 0 deletions alloc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@
#![feature(async_iterator)]
#![feature(bstr)]
#![feature(bstr_internals)]
#![feature(char_internals)]
#![feature(char_max_len)]
#![feature(clone_to_uninit)]
#![feature(coerce_unsized)]
Expand Down Expand Up @@ -135,6 +136,7 @@
#![feature(pattern)]
#![feature(pin_coerce_unsized_trait)]
#![feature(pointer_like_trait)]
#![feature(ptr_alignment_type)]
#![feature(ptr_internals)]
#![feature(ptr_metadata)]
#![feature(set_ptr_value)]
Expand Down
10 changes: 5 additions & 5 deletions alloc/src/raw_vec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use core::marker::PhantomData;
use core::mem::{ManuallyDrop, MaybeUninit, SizedTypeProperties};
use core::ptr::{self, NonNull, Unique};
use core::ptr::{self, Alignment, NonNull, Unique};
use core::{cmp, hint};

#[cfg(not(no_global_oom_handling))]
Expand Down Expand Up @@ -177,7 +177,7 @@ impl<T, A: Allocator> RawVec<T, A> {
/// the returned `RawVec`.
#[inline]
pub(crate) const fn new_in(alloc: A) -> Self {
Self { inner: RawVecInner::new_in(alloc, align_of::<T>()), _marker: PhantomData }
Self { inner: RawVecInner::new_in(alloc, Alignment::of::<T>()), _marker: PhantomData }
}

/// Like `with_capacity`, but parameterized over the choice of
Expand Down Expand Up @@ -409,8 +409,8 @@ unsafe impl<#[may_dangle] T, A: Allocator> Drop for RawVec<T, A> {

impl<A: Allocator> RawVecInner<A> {
#[inline]
const fn new_in(alloc: A, align: usize) -> Self {
let ptr = unsafe { core::mem::transmute(align) };
const fn new_in(alloc: A, align: Alignment) -> Self {
let ptr = Unique::from_non_null(NonNull::without_provenance(align.as_nonzero()));
// `cap: 0` means "unallocated". zero-sized types are ignored.
Self { ptr, cap: ZERO_CAP, alloc }
}
Expand Down Expand Up @@ -465,7 +465,7 @@ impl<A: Allocator> RawVecInner<A> {

// Don't allocate here because `Drop` will not deallocate when `capacity` is 0.
if layout.size() == 0 {
return Ok(Self::new_in(alloc, elem_layout.align()));
return Ok(Self::new_in(alloc, elem_layout.alignment()));
}

if let Err(err) = alloc_guard(layout.size()) {
Expand Down
85 changes: 57 additions & 28 deletions alloc/src/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1043,7 +1043,7 @@ impl String {
#[inline]
#[must_use = "`self` will be dropped if the result is not used"]
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_stable(feature = "const_vec_string_slice", since = "CURRENT_RUSTC_VERSION")]
#[rustc_const_stable(feature = "const_vec_string_slice", since = "1.87.0")]
#[rustc_allow_const_fn_unstable(const_precise_live_drops)]
pub const fn into_bytes(self) -> Vec<u8> {
self.vec
Expand All @@ -1062,7 +1062,7 @@ impl String {
#[must_use]
#[stable(feature = "string_as_str", since = "1.7.0")]
#[rustc_diagnostic_item = "string_as_str"]
#[rustc_const_stable(feature = "const_vec_string_slice", since = "CURRENT_RUSTC_VERSION")]
#[rustc_const_stable(feature = "const_vec_string_slice", since = "1.87.0")]
pub const fn as_str(&self) -> &str {
// SAFETY: String contents are stipulated to be valid UTF-8, invalid contents are an error
// at construction.
Expand All @@ -1085,7 +1085,7 @@ impl String {
#[must_use]
#[stable(feature = "string_as_str", since = "1.7.0")]
#[rustc_diagnostic_item = "string_as_mut_str"]
#[rustc_const_stable(feature = "const_vec_string_slice", since = "CURRENT_RUSTC_VERSION")]
#[rustc_const_stable(feature = "const_vec_string_slice", since = "1.87.0")]
pub const fn as_mut_str(&mut self) -> &mut str {
// SAFETY: String contents are stipulated to be valid UTF-8, invalid contents are an error
// at construction.
Expand Down Expand Up @@ -1134,7 +1134,7 @@ impl String {
/// assert_eq!(string, "abcdecdeabecde");
/// ```
#[cfg(not(no_global_oom_handling))]
#[stable(feature = "string_extend_from_within", since = "CURRENT_RUSTC_VERSION")]
#[stable(feature = "string_extend_from_within", since = "1.87.0")]
pub fn extend_from_within<R>(&mut self, src: R)
where
R: RangeBounds<usize>,
Expand All @@ -1159,7 +1159,7 @@ impl String {
#[inline]
#[must_use]
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_stable(feature = "const_vec_string_slice", since = "CURRENT_RUSTC_VERSION")]
#[rustc_const_stable(feature = "const_vec_string_slice", since = "1.87.0")]
pub const fn capacity(&self) -> usize {
self.vec.capacity()
}
Expand Down Expand Up @@ -1401,11 +1401,14 @@ impl String {
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn push(&mut self, ch: char) {
match ch.len_utf8() {
1 => self.vec.push(ch as u8),
_ => {
self.vec.extend_from_slice(ch.encode_utf8(&mut [0; char::MAX_LEN_UTF8]).as_bytes())
}
let len = self.len();
let ch_len = ch.len_utf8();
self.reserve(ch_len);

// SAFETY: Just reserved capacity for at least the length needed to encode `ch`.
unsafe {
core::char::encode_utf8_raw_unchecked(ch as u32, self.vec.as_mut_ptr().add(self.len()));
self.vec.set_len(len + ch_len);
}
}

Expand All @@ -1425,7 +1428,7 @@ impl String {
#[inline]
#[must_use]
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_stable(feature = "const_vec_string_slice", since = "CURRENT_RUSTC_VERSION")]
#[rustc_const_stable(feature = "const_vec_string_slice", since = "1.87.0")]
pub const fn as_bytes(&self) -> &[u8] {
self.vec.as_slice()
}
Expand Down Expand Up @@ -1702,24 +1705,31 @@ impl String {
#[rustc_confusables("set")]
pub fn insert(&mut self, idx: usize, ch: char) {
assert!(self.is_char_boundary(idx));
let mut bits = [0; char::MAX_LEN_UTF8];
let bits = ch.encode_utf8(&mut bits).as_bytes();

let len = self.len();
let ch_len = ch.len_utf8();
self.reserve(ch_len);

// SAFETY: Move the bytes starting from `idx` to their new location `ch_len`
// bytes ahead. This is safe because sufficient capacity was reserved, and `idx`
// is a char boundary.
unsafe {
self.insert_bytes(idx, bits);
ptr::copy(
self.vec.as_ptr().add(idx),
self.vec.as_mut_ptr().add(idx + ch_len),
len - idx,
);
}
}

#[cfg(not(no_global_oom_handling))]
unsafe fn insert_bytes(&mut self, idx: usize, bytes: &[u8]) {
let len = self.len();
let amt = bytes.len();
self.vec.reserve(amt);
// SAFETY: Encode the character into the vacated region if `idx != len`,
// or into the uninitialized spare capacity otherwise.
unsafe {
core::char::encode_utf8_raw_unchecked(ch as u32, self.vec.as_mut_ptr().add(idx));
}

// SAFETY: Update the length to include the newly added bytes.
unsafe {
ptr::copy(self.vec.as_ptr().add(idx), self.vec.as_mut_ptr().add(idx + amt), len - idx);
ptr::copy_nonoverlapping(bytes.as_ptr(), self.vec.as_mut_ptr().add(idx), amt);
self.vec.set_len(len + amt);
self.vec.set_len(len + ch_len);
}
}

Expand Down Expand Up @@ -1749,8 +1759,27 @@ impl String {
pub fn insert_str(&mut self, idx: usize, string: &str) {
assert!(self.is_char_boundary(idx));

let len = self.len();
let amt = string.len();
self.reserve(amt);

// SAFETY: Move the bytes starting from `idx` to their new location `amt` bytes
// ahead. This is safe because sufficient capacity was just reserved, and `idx`
// is a char boundary.
unsafe {
ptr::copy(self.vec.as_ptr().add(idx), self.vec.as_mut_ptr().add(idx + amt), len - idx);
}

// SAFETY: Copy the new string slice into the vacated region if `idx != len`,
// or into the uninitialized spare capacity otherwise. The borrow checker
// ensures that the source and destination do not overlap.
unsafe {
ptr::copy_nonoverlapping(string.as_ptr(), self.vec.as_mut_ptr().add(idx), amt);
}

// SAFETY: Update the length to include the newly added bytes.
unsafe {
self.insert_bytes(idx, string.as_bytes());
self.vec.set_len(len + amt);
}
}

Expand Down Expand Up @@ -1779,7 +1808,7 @@ impl String {
/// ```
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_stable(feature = "const_vec_string_slice", since = "CURRENT_RUSTC_VERSION")]
#[rustc_const_stable(feature = "const_vec_string_slice", since = "1.87.0")]
pub const unsafe fn as_mut_vec(&mut self) -> &mut Vec<u8> {
&mut self.vec
}
Expand All @@ -1801,7 +1830,7 @@ impl String {
#[inline]
#[must_use]
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_stable(feature = "const_vec_string_slice", since = "CURRENT_RUSTC_VERSION")]
#[rustc_const_stable(feature = "const_vec_string_slice", since = "1.87.0")]
#[rustc_confusables("length", "size")]
pub const fn len(&self) -> usize {
self.vec.len()
Expand All @@ -1821,7 +1850,7 @@ impl String {
#[inline]
#[must_use]
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_stable(feature = "const_vec_string_slice", since = "CURRENT_RUSTC_VERSION")]
#[rustc_const_stable(feature = "const_vec_string_slice", since = "1.87.0")]
pub const fn is_empty(&self) -> bool {
self.len() == 0
}
Expand Down Expand Up @@ -3140,7 +3169,7 @@ impl From<String> for Vec<u8> {
}
}

#[stable(feature = "try_from_vec_u8_for_string", since = "CURRENT_RUSTC_VERSION")]
#[stable(feature = "try_from_vec_u8_for_string", since = "1.87.0")]
impl TryFrom<Vec<u8>> for String {
type Error = FromUtf8Error;
/// Converts the given [`Vec<u8>`] into a [`String`] if it contains valid UTF-8 data.
Expand Down
Loading