Commit Graph

3829 Commits

Author SHA1 Message Date
Jacob Pratt
95bb796b32 Rollup merge of #159864 - zakrad:fix-136797-rc-arc-capacity-overflow, r=JohnTitor
Report "capacity overflow" for oversized Rc<[T]>/Arc<[T]>

Fixes rust-lang/rust#136797.

Building an Rc<[T]>/Arc<[T]> whose header + payload layout exceeds
isize::MAX unwrapped a LayoutError and panicked with "called
Result::unwrap() on an Err value: LayoutError". Vec and Box report
"capacity overflow" here; this makes Rc/Arc do the same.

Used an inline panic!("capacity overflow") rather than raw_vec's
capacity_overflow(), since that helper is cfg'd out under
no_global_oom_handling while these two layout fns still compile there.
2026-07-31 22:25:10 -04:00
Rachel Barker
d3be642d27 Mark a doctest as requiring unwinding
https://github.com/rust-lang/rust/pull/158547 moved `std::io::BufWriter` to
`alloc::io::BufWriter`. That allows it to be used in `no-std` configurations,
and in particular on platforms where unwinding isn't supported.

However one of the doc tests uses `catch_unwind`, which fails on platforms
which cannot unwind. Fix this by copying the magic incantation from a similar
doctest in library/core/src/range.rs
2026-07-29 14:21:35 +01:00
Jacob Pratt
c5ea97ed50 Rollup merge of #157226 - theemathas:stab-box-vec-non-null, r=nia-e
Partially stabilize `box_vec_non_null`

Closes rust-lang/rust#130364

r? libs-api

### What's being stabilized

The following is being stabilized in this PR:

```rust
impl<T: ?Sized> Box<T> {
    pub unsafe fn from_non_null(ptr: NonNull<T>) -> Self { .... }
    pub fn into_non_null(b: Self) -> NonNull<T> { .... }
}
impl<T> Vec<T> {
    pub const unsafe fn from_parts(ptr: NonNull<T>, length: usize, capacity: usize) -> Self { .... }
    pub const fn into_parts(self) -> (NonNull<T>, usize, usize) { .... }
}
```

Note that `Vec::from_parts` and `Vec::into_parts` remain const-unstable behind the `const_heap` feature (like `Vec::from_raw_parts` and `Vec::into_raw_parts`).

The following APIs remain gated behind `allocator_api`
```rust
impl<T: ?Sized, A: Allocator> Box<T, A> {
    pub unsafe fn from_non_null_in(raw: NonNull<T>, alloc: A) -> Self { .... }
    pub fn into_non_null_with_allocator(b: Self) -> (NonNull<T>, A) { .... }
}
impl<T, A: Allocator> Vec<T, A> {
    pub const unsafe fn from_parts_in(ptr: NonNull<T>, length: usize, capacity: usize, alloc: A) -> Self { .... }
    pub const fn into_parts_with_alloc(self) -> (NonNull<T>, usize, usize, A) { .... }
}
```

The following API is split into a new unstable feature in rust-lang/rust#157843, and remains unstable:
```rust
impl<T, A: Allocator> Vec<T, A> {
    pub const fn as_non_null(&mut self) -> NonNull<T> { .... }
}
```

### Implementation History

Most of this feature was ACP'ed in https://github.com/rust-lang/libs-team/issues/418, and implemented in https://github.com/rust-lang/rust/pull/130061. `Vec::as_non_null` was ACP'ed separately in https://github.com/rust-lang/libs-team/issues/440, and implemented in https://github.com/rust-lang/rust/pull/130624.

### Potential issues

* Should `Vec::from_parts` and `Vec::into_parts` be the name used for this? Or should those names be used for functions that take/return `Box<[MaybeUninit<T>]>`? (Raised at https://github.com/rust-lang/rust/issues/130364#issuecomment-2357276951)
* Should these function names be named `non_null` or `nonnull`? (Raised at https://github.com/rust-lang/rust/issues/130364#issuecomment-4525680948. See https://github.com/rust-lang/rust/issues/154237#issuecomment-4120073976.)
* Will the methods on `Vec` collide with anything via autoderef?
2026-07-28 20:09:36 -04:00
Jonathan Brouwer
82b7eea6d0 Rollup merge of #159776 - Syvraa:main, r=LawnGnome
remove const hack in alloc

Seems like this change was missed when other const hacks were removed.
2026-07-28 21:07:57 +02:00
Jules Bertholet
e7d2b7ebda Correct tracking issue for casefold feature 2026-07-28 00:28:24 -04:00
Jonathan Brouwer
e7e934e096 Rollup merge of #159821 - SzilvasiPeter:main, r=Darksonn
Update expect message using the recommended style in binary_heap module

Related issue: rust-lang/rust#159751
2026-07-27 11:58:11 +02:00
Peter Szilvasi
10a5e9da29 Update error messages for overflow and out of bound cases 2026-07-27 07:17:16 +00:00
Jonathan Brouwer
cc06a86bf6 Rollup merge of #159917 - bend-n:split_at_capacity_constifications, r=jhpratt
spare capacity mut constification

the better to allocate with
2026-07-26 15:47:26 +02:00
Jonathan Brouwer
f3daf4d3ac Rollup merge of #159882 - Colepng:main, r=Darksonn
Update expect messages in library/alloc/boxed.rs and library/alloc/string.rs to follow the style guide

Related issue: rust-lang/rust#159751

Updates the expect messages in library/alloc/boxed.rs and library/alloc/string.rs to follow the style guide.
2026-07-26 15:47:22 +02:00
Jonathan Brouwer
d74368208e Rollup merge of #159853 - asder8215:cstr_expect, r=fee1-dead
Updated expect messages for `CString` struct and method documentation

Completes a task with rust-lang/rust#159751. Updates the expect messages in `library/alloc/src/ffi/c_str.rs`.
2026-07-26 15:47:20 +02:00
Peter Szilvasi
c46ab28fc3 Update expect message in library/alloc/src/collections/vec_deque/mod.rs 2026-07-26 13:35:11 +00:00
Peter Szilvasi
91cead3cb0 Update expect message using the recommended style in binary_heap module 2026-07-26 15:26:56 +02:00
Syvraa
6a7e3d23d8 remove const hack in alloc 2026-07-26 14:52:45 +02:00
Jacob Pratt
c604cd98b2 Rollup merge of #159720 - RalfJung:global-allocator-opsem-magic, r=aapoalas,nia-e,nikic
document #[global_allocator] constraints

`#[global_allocator]` is opsem magic. For instance, even if we do
```rust
use std::alloc::System;

#[global_allocator]
static ALLOC: System = System;
```
it is still UB to allocate via `std::alloc::alloc()` and deallocate via `System.dealloc()`. This is because we add special magic LLVM attributes in the `#[global_allocator]` machinery that tell LLVM about our global allocation methods so it can optimize accordingly, and mixing allocators is against those rules.

Cc @rust-lang/opsem @rust-lang/lang @nia-e @maxdexh
@nikic is this enough to ensure that adding your intrinsics is sound?
2026-07-26 00:21:44 -04:00
bendn
b8fd8a885e spare capacity mut constification 2026-07-25 23:57:55 +07:00
Cole Kauder-McMurrich
36ef11a72c Update expect messages in library/alloc/boxed.rs and library/alloc/string.rs to follow the style guide 2026-07-25 01:06:27 -04:00
Mahdi Ali-Raihan
a32fa442ef Updated expect messages for CString struct and method documentation 2026-07-24 18:47:33 -04:00
zakrad
024bd5e9dc Report "capacity overflow" for oversized Rc<[T]>/Arc<[T]>
Constructing an Rc<[T]> or Arc<[T]> whose header + payload layout exceeds
isize::MAX unwrapped a LayoutError, panicking with the opaque "called
`Result::unwrap()` on an `Err` value: LayoutError". Match Vec and Box by
reporting "capacity overflow" instead, and add regression tests.
2026-07-24 23:40:16 +03:30
Jacob Pratt
af4cac9fd5 Rollup merge of #159271 - Rachit2323:fix-titlecase-ascii-fastpath, r=clarfonthey
str: add ASCII fast path to word_to_titlecase

The word_to_titlecase function had a FIXME comment since a long time asking to add a fast path for ASCII text.

Before this change, even simple English text like "hello world" was going through slow Unicode lookup tables. That was unnecessary.

This fixes it by using the same trick that to_lowercase already uses — plain English letters are now handled much faster, and only Greek/Chinese/etc still use the Unicode tables.

No behavior changes, just faster for normal English text.
2026-07-24 01:59:26 -04:00
Jacob Pratt
649cfef8d8 Rollup merge of #155795 - Lars-Schumann:const-vec-macro, r=oli-obk
constify `vec![1, 2, 3]` macro

Tracking issues:
`const_heap`: https://github.com/rust-lang/rust/issues/79597

makes all the parts needed for non-empty `vec![]` macros const:

`alloc::boxed::box_assume_init_into_vec_unsafe`
`alloc::boxed::Box::assume_init`
`alloc::boxed::Box::into_raw_with_allocator`
`alloc::boxed::Box::new_uninit`
`alloc::slice::[T]::into_vec`

Note that this does not allow for the use of the `vec![(); 4]` arm of this macro to be used in const-eval, since that uses specialization (spec and const traits don't really like each other so I didn't want to touch any of that in this).
2026-07-24 01:59:24 -04:00
Ralf Jung
8242b333da document #[global_allocator] constraints 2026-07-23 17:37:48 +02:00
Lars Schumann
b1342c9217 constify vec![1, 2, 3] macro arm functions 2026-07-22 22:14:58 +00:00
Jacob Pratt
0bb7d378d8 Rollup merge of #159652 - maxdexh:bugfix/unique-arc-uninit-drop-oom, r=Darksonn
Remove `cfg(not(no_global_oom_handling))` from the `Drop` impl of `UniqueArcUninit`

Fixes rust-lang/rust#159651
2026-07-21 20:59:28 -04:00
Max Dexheimer
8ae35e20e8 Remove the cfg(not(no_global_oom_handling)) from Drop impl 2026-07-21 12:42:50 +02:00
Jonathan Brouwer
66dc1b3042 Rollup merge of #159471 - kpreid:constalloc, r=clarfonthey
Make `Global` and `System` allocators unstably implement `const Clone + const Default`.

Allocators implementing `const Default` is useful for generically constructing empty collections inside of constants:

```rust
struct Foo<A: Allocator>(Vec<i32, A>);
impl<A: Allocator + const Default> Foo<A> {
    pub const EMPTY: Self = Self(Vec::new_in(A::default()));
}
```

`const Clone` is not strictly necessary to permit such constants to exist, but may make more complex code easier to write (e.g. so a const constructor can accept one allocator and clone it).

@rustbot label +A-allocators
2026-07-21 12:24:56 +02:00
Zachary Harrold
6ef1cf3cf0 Add inline to new BufWriter method 2026-07-20 22:17:16 +10:00
Zachary Harrold
9d38fe5be7 Add inline to new BufReader method 2026-07-20 22:16:52 +10:00
Zac Harrold
69b380676d Standardize on pub(super) instead of pub(in crate::io)
Co-Authored-By: Clar Fon <15850505+clarfonthey@users.noreply.github.com>
2026-07-20 17:14:06 +10:00
Zac Harrold
3739d0425b Make Buffer private 2026-07-20 17:14:06 +10:00
Zac Harrold
295f7f464a Use Vec::<u8>::try_extend_from_slice_of_bytes instead of unsafe code
Co-Authored-By: Clar Fon <15850505+clarfonthey@users.noreply.github.com>
2026-07-20 17:14:04 +10:00
Zac Harrold
f012e40a83 Use String::try_push_str instead of unsafe code
Co-Authored-By: Clar Fon <15850505+clarfonthey@users.noreply.github.com>
2026-07-20 15:00:07 +10:00
Zac Harrold
44d9de29f2 Reduce API surface of alloc::io reexports from core::io 2026-07-20 15:00:07 +10:00
Zac Harrold
4f8a2a9245 Reduce API surface of alloc::io::read 2026-07-20 15:00:07 +10:00
Zac Harrold
4af788e0ba Reduce API surface of alloc::io::util 2026-07-20 15:00:07 +10:00
Zac Harrold
f415df6e72 Reduce API surface of Buffer
None of the currently public methods are accessible outside `std`, and are unused within. Therefore, they can be restricted to internal use.
2026-07-20 15:00:07 +10:00
Zac Harrold
f6d8df82f2 Move std::io::buffered to alloc::io 2026-07-20 15:00:07 +10:00
Zac Harrold
7c0c4efec8 Prepend read_until and skip_until with default_
More consistent with the default functions for `Read`

Co-Authored-By: Clar Fon <15850505+clarfonthey@users.noreply.github.com>
2026-07-19 12:14:27 +10:00
Zac Harrold
982072a7c7 Fix documentation links to BufRead 2026-07-19 07:32:45 +10:00
Zac Harrold
e33662abd6 Move std::io::BufRead to alloc::io 2026-07-19 07:32:45 +10:00
Zac Harrold
5de65af8f0 Move std::io::read_to_string to alloc::io 2026-07-18 13:20:59 +10:00
Kevin Reid
1c7eaf95a0 Make Global and System allocators implement const Clone + const Default.
This is useful for generically constructing empty collections:

    struct Foo<A: Allocator>(Vec<i32, A>);
    impl<A: Allocator + const Default> Foo<A> {
        pub const EMPTY: Self = Self(Vec::new_in(A::default()));
    }
2026-07-17 15:03:01 -07:00
Jonathan Brouwer
fa73a93bed Rollup merge of #158544 - bushrat011899:core_io_read, r=clarfonthey
Move `std::io::Read` to `alloc::io`

ACP: https://github.com/rust-lang/libs-team/issues/755
Tracking issue: https://github.com/rust-lang/rust/issues/154046
Split From: https://github.com/rust-lang/rust/pull/156527
~~Blocked On: https://github.com/rust-lang/rust/pull/158541~~

## Description

Moves `std::io::Read` to `alloc::io`. This is mostly a direct cut and paste, but with a large diff due to how many implementations need to be moved into `alloc`. Blocked on rust-lang/rust#158541.

There is some new code written for some of the `Read` implementations to account for the `no_global_oom_handling` configuration, since `Vec::extend_from_slice` and `String::push_str` are unavailable. I've highlighted all of these such instances with review comments for clarity.

---

## Notes

* No AI tooling of any kind was used during the creation of this PR.
* Please see https://github.com/rust-lang/rust/issues/154046#issuecomment-4416678427 for a review order and broader context for this PR.
2026-07-17 23:17:28 +02:00
Rachit2323
28d994a835 str: add ASCII fast path to word_to_titlecase 2026-07-15 16:03:01 +05:30
Jacob Pratt
2d4ae662df Rollup merge of #158608 - mejrs:opaque, r=estebank
Implement `#[diagnostic::opaque]` attribute to hide backtraces of macros.

r? @estebank

There are some more places where we can use this, for example 345632878c/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs (L623-L639) but those turned out to be a little complicated so are left for followup prs.

Tracking issue: rust-lang/rust#158813
2026-07-14 23:23:07 -04:00
Jacob Pratt
319376c7e5 Rollup merge of #156220 - cammeresi:20260505-truncate-to-range, r=nia-e
Implement `VecDeque::truncate_to_range`

Tracking issue: rust-lang/rust#156215
2026-07-14 23:23:06 -04:00
Mark Rousskov
61a4e6029c replace-version-placeholder 2026-07-13 18:04:39 -04:00
Jonathan Brouwer
a22bffb357 Rollup merge of #158876 - maxdexh:bugfix-arc-make-mut, r=Mark-Simulacrum
Fix multiple logic bugs in `Arc::make_mut`

See the following (nightly-specific) issues:
- Fixes rust-lang/rust#158875
- Fixes rust-lang/rust#155746
- Fixes rust-lang/rust#157203
2026-07-11 19:05:15 +02:00
Sidney Cammeresi
ba313ddd1d Implement VecDeque::retain_range 2026-07-11 07:08:56 -07:00
Sidney Cammeresi
ec8c18fdb8 Un-copy-paste Dropper in VecDeque code 2026-07-11 07:08:53 -07:00
Zac Harrold
d1bdecc18d Replace alloc::io::read::Guard with core::mem::DropGuard
Co-Authored-By: Clar Fon <15850505+clarfonthey@users.noreply.github.com>
2026-07-11 09:23:01 +10:00