Commit Graph

3985 Commits

Author SHA1 Message Date
Jonathan Brouwer
1b7b9eaf79 Rollup merge of #160436 - edwloef:stabilize-box-take, r=Darksonn
stabilize `Box::take`

Tracking issue: rust-lang/rust#147212

There hasn't been any activity on the tracking issue for a while, and this is a pretty small feature, so opening this to hopefully get a FCP started.

Closes: rust-lang/rust#147212
2026-09-22 22:50:28 +02:00
Jonathan Brouwer
923f22ad6c Rollup merge of #163136 - mejrs:lint_maintenance, r=jhpratt
library: prune allowed lints
2026-09-22 13:23:36 +02:00
mejrs
16ede108f0 library: prune allowed lints 2026-09-22 00:42:42 +02:00
Jonathan Brouwer
2f931d4166 Rollup merge of #162600 - maxdexh:box-generalize, r=clarfonthey
Make the last non-breaking box impl generalizations

Follow-up to rust-lang/rust#161946

r? clarfonthey
2026-09-21 17:34:10 +02:00
bors
12c4d3f34d Auto merge of #162804 - maxdexh:nuke-unique-in-vec, r=hanna-kruppe
Remove usages of `Unique` from `RawVec`



See [zulip](https://rust-lang.zulipchat.com/#narrow/channel/219381-t-libs/topic/Can.20we.20nuke.20.60Unique.60.3F/with/624141418).

Probably needs a perf run, because it touches code that might be very sensitive to build times and debug mode

r? libs
2026-09-20 13:11:30 +00:00
Max Dexheimer
16337b6cfd Remove usages of Unique from RawVec 2026-09-20 12:58:26 +02:00
Jonathan Brouwer
012e0bba49 Rollup merge of #162733 - maxdexh:unique-arc-pub-apis, r=nia-e
Add useful APIs to `Unique(Arc|Rc)`

Some of these we already had private methods for (only used for `(try_)map`), some of these (or lack thereof) (namely the `try_new` apis) prevented me from using `UniqueArc` in other parts of std.

cc rust-lang/rust#112566
2026-09-19 08:45:33 +02:00
Max Dexheimer
e727033b47 Guard types with unstable allocator params ahead of partial stabilization 2026-09-18 16:37:01 +02:00
Jonathan Brouwer
e7feb41dcd Rollup merge of #162766 - maxdexh:unleak-considered-harmful, r=hanna-kruppe,saethlin
stop unleaking `&mut`s in std and the compiler

As discussed on [zulip](https://rust-lang.zulipchat.com/#narrow/channel/136281-t-opsem/topic/What.20is.20the.20current.20state.20of.20unleaking.20a.20.60Box.3CT.2C.20Global.3E.60.3F/with/623860839), this PR removes all the dubious uses (I could find) of `Box::leak` from rustc and std

r? libs
2026-09-14 19:23:28 +02:00
Jonathan Brouwer
4d21806694 Rollup merge of #162763 - maxdexh:remove-into-unique, r=RalfJung
Remove `Box::into_unique`

As discussed on [zulip](https://rust-lang.zulipchat.com/#narrow/channel/136281-t-opsem/topic/What.20is.20the.20current.20state.20of.20unleaking.20a.20.60Box.3CT.2C.20Global.3E.60.3F/with/623860839), this PR removes the `Box::into_unique` method and also adds a test for `into_raw_with_allocator`.

Note that all uses of `into_unique` were already removed from std in rust-lang/rust#162732. The only remaining use was a Miri test.

I didn't copy over the "lose the tag" operation for the `into_raw_with_allocator` test, because the file you wanted me to put this in doesn't have `-Zmiri-permissive-provenance` ^^

r? RalfJung
2026-09-14 19:23:27 +02:00
Max Dexheimer
fe15c63bed stop unleaking &muts in std and the compiler 2026-09-14 15:44:58 +02:00
Jonathan Brouwer
1a343b461e Rollup merge of #162735 - maxdexh:boundless-fun, r=jhpratt
Remove pointless `A: Allocator` bounds in boxed.rs

bottom text
2026-09-14 15:16:06 +02:00
Max Dexheimer
1a218186be Remove Box::into_unique, add a test for into_raw_with_allocator 2026-09-14 15:08:52 +02:00
Max Dexheimer
f0eb4b571c Remove pointless A: Allocator bounds in boxed.rs 2026-09-13 21:58:10 +02:00
Max Dexheimer
1629bcdb5d Add useful APIs to Unique(Arc|Rc) 2026-09-13 21:24:42 +02:00
Max Dexheimer
d559cfd345 Fix unsound reborrows of raw ptrs from custom allocators 2026-09-13 18:53:29 +02:00
Roland Xu
69fdca8af6 Rollup merge of #161520 - yoshuawuyts:stabilize-dropguard, r=nia-e
Stabilize `core::mem::DropGuard`

Closes https://github.com/rust-lang/rust/issues/144426. This PR stabilizes `core::mem::DropGuard`, as per the comment in https://github.com/rust-lang/rust/issues/144426#issuecomment-5332324003:

> [nia-e]: We discussed this in today's libs meeting - DropGuard is a good name, and we agreed dismiss is Good Enough & better than the other options. Feel free to send a stabilisation PR & ask us to open FCP there!

Thanks!

r? @nia-e
2026-09-13 09:39:00 +08:00
EFanZh
d774bfa443 Stabilize Vec::from_fn 2026-09-12 19:32:48 +08:00
Jonathan Brouwer
5a64414b84 Rollup merge of #161430 - cuviper:fmt_numbuffer, r=JohnTitor
Re-export `core::fmt::NumBuffer` in `alloc` (and `std`)

We just stabilized `core::fmt::NumBuffer` in Rust 1.98, but it seems to be a simple oversight that this was not also re-exported in `alloc::fmt` (and `std` just re-exports that whole module). Let's correct that.

I'm marking this stable right away, although I don't think the later `since` version will be properly rendered in docs for a re-export. I'm not sure it's worth trying to clarify that in freeform documentation.
2026-09-11 21:15:02 +02:00
Max Dexheimer
79a93e7b03 Make the last non-breaking box impl generalizations 2026-09-10 17:31:15 +02:00
Jacob Pratt
5df503266f Rollup merge of #161946 - nia-e:more-box-impls, r=clarfonthey
Generalise (most) impls on `Box`

Resolves the trait impl concern for rust-lang/rust#156882; `Default` wasn't touched since changing that would be breaking, but hopefully all of this should be fine - I'll do a crater run to be sure. Certain impls that were for one reason or another Annoying to generalise (e.g. `Clone for Box<Path>`) were also untouched since I believe we can add those in the future, as they're on concrete types.

r? clarfonthey
2026-09-09 14:05:26 -04:00
Max Dexheimer
8bd0a5aff2 Refactor vec::IntoIter::into_vecdeque to fix unsoundness 2026-09-08 13:35:46 +02:00
Jonathan Brouwer
9ca49d6252 Rollup merge of #162212 - a1phyr:box_random, r=joboet
Implement `Rng` for `Box`

Tracking issue: https://github.com/rust-lang/rust/issues/130703

Like https://github.com/rust-lang/rust/pull/159435, this implementation must be implemented before the stabilization of `Rng`.

r? @joshtriplett
2026-09-04 22:29:12 +02:00
Jonathan Brouwer
8820516fcc Rollup merge of #162289 - nia-e:alloc-safety-comments-part-2, r=Darksonn
alloc: a bunch of safety comments

Following up from rust-lang/rust#160941. Triaging this is what found the errors in rust-lang/rust#162285 & rust-lang/rust#162286. More to come, but I didn't want to make the review effort too high on any single PR.

r? libs
2026-09-04 22:29:03 +02:00
Jonathan Brouwer
b48235859e Rollup merge of #162286 - nia-e:string-splice-nounwind, r=Darksonn
string: don't unwind prematurely

`splice` on a vec can technically unwind (since we still say `handle_alloc_error` *may* unwind in the future, and nightly users could trigger this via setting the alloc error hook) which would expose a string in an invalid state during `replace_range`. This adds an abort guard around it to ensure this is never triggered.

r? libs
2026-09-04 22:29:02 +02:00
Jonathan Brouwer
2e0b41bd13 Rollup merge of #162285 - nia-e:box-map-zst, r=JohnTitor
box: fixup map/try_map deallocate calls

`Box::{map, try_map}` unsoundly called `deallocate` on the previous box's pointer, even if it was a ZST. This was probably okay for `Global` but it's definitely not for arbitrary custom allocators.

r? libs
2026-09-04 22:29:02 +02:00
Nia Deckers
e57809063d typo 2026-09-04 14:24:27 +02:00
Nia Deckers
c66f1501c9 drop unnecessary feature gate 2026-09-04 14:13:47 +02:00
Nia Deckers
1c48bd65b3 review 2026-09-04 14:12:07 +02:00
Nia Deckers
22894e4c30 reserve ahead of time 2026-09-04 13:13:29 +02:00
Nia Deckers
b1a9fcaead alloc: a bunch of safety comments 2026-09-04 12:59:14 +02:00
Nia Deckers
8f1e14781d string: don't unwind prematurely 2026-09-04 11:57:26 +02:00
Nia Deckers
2a2b4c654e box: fixup map/try_map deallocate calls 2026-09-04 11:27:48 +02:00
Jonathan Brouwer
695248d0ed Rollup merge of #161893 - maxdexh:unique-arc-map, r=nia-e
Add custom allocator support to `(try_)map` on `UniqueArc` and `UniqueRc`

Follow-up to rust-lang/rust#161617.

This one required me to add allocator support to a lot more methods.
Probably good for them to have it for future additions ^^

The old, allocator-free methods went unused from this change and I had to remove them because we don't allow warnings (they are trivial to implement on top of the allocator ones). This had the side effect of making the diff a bit weird. Sorry!

r? nia-e
2026-09-03 20:02:52 +02:00
Benoît du Garreau
aea90f17e1 Implement Rng for Box 2026-09-03 20:02:13 +02:00
bors
edc52f87c2 Auto merge of #162128 - clarfonthey:revert-drop-guard, r=clarfonthey
Revert "Use `drop_guard` in some places in {core,alloc,std}"

cc @panstromek @GrigorenkoPV 

Reverts this PR due to perf issues, so that a fix can be verified to not affect perf. Apologies for not initially running perf; kinda tunnel-visioned "this just does the same thing" without considering the changes from non-generic functions to generic closures.
2026-09-02 01:22:53 +00:00
Jonathan Brouwer
51998dbbf8 Rollup merge of #162102 - DanielEScherzer:less-unsafe-in-alloc, r=clarfonthey
`alloc` crate: shrink undocumented `unsafe` blocks

Reduce the scope of `unsafe` blocks that are not yet documented by moving safe operations out of the blocks, making it easier to add the missing documentation in the future.
2026-09-01 21:26:19 +02:00
Jonathan Brouwer
e2897d777d Rollup merge of #162073 - camsteffen:lib-eat-never, r=clarfonthey
Change some `Infallible` to `!` in std

I believe this desirable since we recommend `!` over `Infallible`, so std follows its own advice. Most changes are to unstable features, but not all. Similar changes in compiler have to wait for a bootstrap update.
2026-09-01 21:26:17 +02:00
Max Dexheimer
7791246b91 Add custom allocator support to (try_)map on UniqueArc and UniqueRc 2026-09-01 19:50:35 +02:00
Cameron Steffen
dd132214ed Dogfood never type in std 2026-09-01 08:57:20 -05:00
ltdk
7755d45ec9 Revert "Use drop_guard in some places in {core,alloc,std}"
This reverts commit 4f404c1f7e.
2026-09-01 09:37:27 -04:00
Jonathan Brouwer
dcb658289c Rollup merge of #160534 - Qelxiros:stabilize-smart-pointer-map, r=nia-e
stabilize smart pointer map functions

Tracking issue: rust-lang/rust#144419
@rustbot modify labels: +T-libs-api
2026-09-01 13:27:36 +02:00
Daniel Scherzer
b5e834472f alloc crate: shrink undocumented unsafe blocks
Reduce the scope of `unsafe` blocks that are not yet documented by moving safe
operations out of the blocks, making it easier to add the missing documentation
in the future.
2026-08-31 21:24:01 -07:00
Yosh
c3d54c6eec Stabilize core::mem::DropGuard
Signed-off-by: Yosh <github@yosh.is>
2026-08-31 12:12:58 +02:00
Jacob Pratt
99e83a5e18 Rollup merge of #161379 - steffahn:extend_trait_param_name, r=JohnTitor
Use better generic type parameter names for `Extend` and `FromIterator`

Change
```rs
pub trait Extend<A> {
    fn extend<T: IntoIterator<Item = A>>(&mut self, iter: T);
    …
}
```
to
```rs
pub trait Extend<T> {
    fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I);
    …
}
```

to be more consistent with common use of `T` as the item type in containers, and their `Extend` impls; and use `I` as the name for the `IntoIterator` type.

also do the basically the same thing for `FromIterator<A>`→`FromIterator<T>` as well

cases of these parameters in trait impls for the abovementioned traits.

These changes obviously don't change/break behavior of the traits and its users, but the improve the way the documentation of the traits renders (the improvement is the more sensible and more consistent names for the parameters). The only downside I'm aware of (besides that this is touching quite a few files..) is that this does affect some link anchor names in *some* cases. E.g.
```diff
- impl<A, V: FromIterator<A>> FromIterator<Option<A>> for Option<V> {
+ impl<T, V: FromIterator<T>> FromIterator<Option<T>> for Option<V> {
```
would mean that [doc.rust-lang.org/core/iter/trait.FromIterator.html#impl-FromIterator<Option\<A>>-for-Option\<V>](https://doc.rust-lang.org/core/iter/trait.FromIterator.html#impl-FromIterator%3COption%3CA%3E%3E-for-Option%3CV%3E) no longer works, as it changes `…#impl-FromIterator<Option<A>>-for-Option<V>` to `…#impl-FromIterator<Option<T>>-for-Option<V>`
2026-08-31 02:24:56 -04:00
Frank Steffahn
9bca736808 More consistent use of variable names for trait implementations 2026-08-31 01:11:58 +02:00
Pavel Grigorenko
4f404c1f7e Use drop_guard in some places in {core,alloc,std} 2026-08-30 17:08:08 +03:00
Jeremy Smart
82ee18a644 stabilize map functions 2026-08-29 17:34:04 -04:00
Guillaume Gomez
a083cee009 Rollup merge of #161975 - matthew-demidoff:btree-split-off-panic-safety, r=nia-e
Abort instead of unwinding out of an inconsistent BTreeMap::split_off

Fixes rust-lang/rust#158165. Supersedes rust-lang/rust#161784, which I had to abandon after a bad force-push from a shallow clone left its head detached.

`BTreeMap::split_off` runs the caller's `Ord`/`Borrow` impl via `search_node` inside `Root::split_off`'s descent. After the first `move_suffix`, the two roots alias the same values through structurally invalid trees until the borders are fixed; a comparator panic there unwinds with a stale length and double-frees on later iteration or drop. It is reachable from `#![forbid(unsafe_code)]` on stable (reproducer on the issue).

Guard the descent loop with an abort-on-panic `PanicGuard`, as `btree::mem::replace` already does. `catch_unwind` isnt available in `alloc` (no_std), and I kept an inline guard rather than the unstable `DropGuard`. It is armed once before the loop; the first `search_node` stays outside it, since a panic there can still unwind safely (nothing has moved yet).

Verified with Miri: the reproducer goes from a double-free to a clean abort, and normal multi-level splits are unaffected. Adds a happy-path regression test.

Credit to @ostrowr for the report and to rust-lang/rust#158710 for the original approach.

r? @nia-e
2026-08-29 22:46:00 +02:00
Matthew Demidoff
303dafdc11 Abort instead of unwinding out of an inconsistent BTreeMap::split_off
After the first move_suffix in Root::split_off, the source and result
trees share values through two temporarily invalid structures. If a
later key comparison panics, unwinding leaves the map with a stale
length over a partially detached tree, and consuming iteration then
double-frees the shared values, reachable from safe code.

Guard the descent loop with a mem::DropGuard that aborts on unwind,
armed before the first move_suffix and dismissed once the borders are
fixed.
2026-08-29 19:19:26 +02:00