Commit graph

98 commits

Author SHA1 Message Date
Lukas Bergdoll
2f3b952349 Stabilize assert_matches 2026-02-11 14:13:44 +01:00
Stuart Cook
a57663ea65
Rollup merge of #151756 - Voultapher:fix-box-retag-in-sort, r=Mark-Simulacrum
Avoid miri error in `slice::sort` under Stacked Borrows

See comment in code.

Fixes: https://github.com/rust-lang/rust/issues/151728
2026-02-02 10:28:29 +11:00
Max Heller
bae7a199f1
Address review comments and fix tests 2026-01-30 09:55:53 -05:00
Max Heller
9928723bff
Implement BinaryHeap::pop_if() 2026-01-29 10:20:34 -05:00
Lukas Bergdoll
ce03e7b33a Avoid miri error in slice::sort under Stacked Borrows
See comment in code.

Fixes: https://github.com/rust-lang/rust/pull/131065
2026-01-28 14:55:29 +01:00
Jeremy Smart
b0d96492d0
fix undefined behavior in VecDeque::splice 2026-01-27 19:30:37 -05:00
Stuart Cook
956ebbde20
Rollup merge of #151383 - cyrgani:no-internal-deprecation, r=scottmcm
remove `#[deprecated]` from unstable & internal `SipHasher13` and `24` types

These types are unstable and `doc(hidden)` (under the internal feature `hashmap_internals`). Deprecating them only adds noise (`#[allow(deprecated)]`) to all places where they are used, so this PR removes the deprecation attributes from them.

It also includes a few other small cleanups in separate commits, including one I overlooked in rust-lang/rust#151228.
2026-01-27 12:50:52 +11:00
Lukas Bergdoll
58be5d6620 Move assert_matches to planned stable path 2026-01-21 23:17:24 +01:00
cyrgani
0adf24ac20 remove #[deprecated] from unstable & internal SipHasher13&24 2026-01-19 21:24:36 +00:00
Jacob Pratt
99b29620ca
Rollup merge of #148769 - stabilize/alloc_layout_extra, r=scottmcm
Stabilize `alloc_layout_extra`

Tracking issue: rust-lang/rust#55724
FCP completed in https://github.com/rust-lang/rust/issues/55724#issuecomment-3447699364
Closes rust-lang/rust#55724

----

As per https://github.com/rust-lang/rust/issues/55724#issuecomment-3403555985,
- `repeat_packed` and `extend_packed` are unchanged
- `repeat` now excludes trailing padding on the last element from the total array size
- `dangling` renamed to `dangling_ptr`
- `padding_needed_for` not stabilized, changed to accept `Alignment` instead of `usize` and moved to the `ptr_aligment_type` feature flag (tracking issue: rust-lang/rust#102070)
2026-01-18 03:16:44 -05:00
Lukas Bergdoll
506762f3ff Explicitly export core and std macros
Currently all core and std macros are automatically added to the prelude
via #[macro_use]. However a situation arose where we want to add a new macro
`assert_matches` but don't want to pull it into the standard prelude for
compatibility reasons. By explicitly exporting the macros found in the core and
std crates we get to decide on a per macro basis and can later add them via
the rust_20xx preludes.
2026-01-13 08:47:48 +01:00
Pavel Grigorenko
e212560317 Stabilize alloc_layout_extra 2026-01-11 16:39:18 +03:00
Matthias Krüger
57da460fc7
Rollup merge of #150781 - pr/cleanup-rand-usages, r=Mark-Simulacrum
Use `rand` crate more idiomatically

Small cleanup, found while working on something else.
We were using `rand` un-idiomatically in a couple of places, and it was bugging me...
2026-01-11 09:56:40 +01:00
Zalathar
50813939e4 Don't run the longer partial-sort tests under Miri 2026-01-11 12:04:46 +11:00
Urgau
65c0847f2d
Rollup merge of #149318 - slice_partial_sort_unstable, r=tgross35
Implement partial_sort_unstable for slice

This refers to https://github.com/rust-lang/rust/issues/149046.
2026-01-09 23:28:15 +01:00
tison
45e0fbf7c5
Implement partial_sort_unstable for slice
Signed-off-by: tison <wander4096@gmail.com>
Co-Authored-By: Orson Peters <orsonpeters@gmail.com>
Signed-off-by: tison <wander4096@gmail.com>
2026-01-09 09:58:08 +08:00
Yotam Ofek
f82dd820a5 Use rand crate more idiomatically 2026-01-07 22:31:33 +02:00
bors
74fd7516da Auto merge of #147893 - fee1-dead-contrib:constheapheapheap, r=oli-obk
`Vec::push` in consts MVP

Example:

```rust
const X: &'static [u32] = {
    let mut v = Vec::with_capacity(6);
    let mut x = 1;
    while x < 42 {
        v.push(x);
        x *= 2;
    }
    assert!(v.len() == 6);
    v.const_make_global()
};

assert_eq!([1, 2, 4, 8, 16, 32], X);
```

Oh this is fun...

* We split out the implementation of `Global` such that it calls `intrinsics::const_allocate` and `intrinsics::const_deallocate` during compile time. This is achieved using `const_eval_select`
* This allows us to `impl const Allocator for Global`
* We then constify everything necessary for `Vec::with_capacity` and `Vec::push`.
* Added `Vec::const_make_global` to leak and intern the final value via `intrinsics::const_make_global`. If we see any pointer in the final value of a `const` that did not call `const_make_global`, we error as implemented in rust-lang/rust#143595.

r? `@rust-lang/wg-const-eval`

To-do for me:
* [x] Assess the rustdoc impact of additional bounds in the method
* [x] ~~Increase test coverage~~ I think this is enough for an unstable feature.
2026-01-06 11:39:17 +00:00
Antoni Spaanderman
7e425b8985
Add specialization for deque1.prepend(deque2.drain(range))
This is used when moving elements between `VecDeque`s
This pattern is also used in examples of `VecDeque::prepend`. (see its docs)
2026-01-02 16:05:42 +01:00
Deadbeef
47864e80cb address review comments; fix CI 2026-01-01 19:17:11 -05:00
Deadbeef
3982d3e706 Vec::push in consts MVP 2026-01-01 19:17:11 -05:00
bors
0e89999425 Auto merge of #147247 - Qelxiros:vecdeque_splice, r=Mark-Simulacrum
add VecDeque::splice

Tracking issue: rust-lang/rust#146975
2025-12-30 19:18:37 +00:00
Jonathan Brouwer
596e1e3f88
Rollup merge of #150344 - hkBst:cleanup-linked-list, r=jhpratt
Cleanup linked list

 - Replaces some checked_sub().unwrap_or(0) with saturating_sub().
 - Replaces NonNull::from(Box::leak(node)) with Box::into_non_null(node)
2025-12-30 10:42:28 +01:00
Marijn Schouten
eea3d794ff LinkedList: use Box::into_non_null_with_allocator 2025-12-29 19:08:34 +00:00
Jeremy Smart
0763954226
add VecDeque::splice 2025-12-29 13:25:56 -05:00
Jonathan Brouwer
3c7ffa5dd1
Rollup merge of #149447 - theemathas:string-replace_range, r=Mark-Simulacrum
Rewrite `String::replace_range`

This simplifies the code, provides better panic messages, and avoids an integer overflow.
2025-12-28 18:16:09 +01:00
Chris Denton
735c45eda4
Rollup merge of #149272 - DrAsu33:fix-vec-iter-zst-alignment-148682, r=Mark-Simulacrum
Fix vec iter zst alignment

Closes rust-lang/rust#148682
2025-12-14 09:18:28 +00:00
DrAsu33
34392a99c0 Fix(alloc): Correctly handle ZST alignment for IntoIter::nth_back
This commit consolidates all changes, including the core logic fix for IntoIter::nth_back and the addition of the Miri regression test in `library/alloctests/tests/vec.rs`, to prevent Undefined Behavior (UB) when dealing with highly-aligned Zero-Sized Types.
2025-12-09 07:56:26 +00:00
Theemathas Chirananthavat
5f5286beb2 Rewrite String::replace_range
This simplifies the code, provides better panic messages,
and avoids an integer overflow.
2025-12-08 17:38:45 +07:00
bors
646a3f8c15 Auto merge of #149125 - zachs18:btreemap-eq-perf, r=workingjubilee
In `BTreeMap::eq`, do not compare the elements if the sizes are different.

Reverts rust-lang/rust#147101 in library/alloc/src/btree/

rust-lang/rust#147101 replaced some instances of code like `a.len() == b.len() && a.iter().eq(&b)` with just `a.iter().eq(&b)`, but the optimization that PR introduced only applies for `TrustedLen` iterators, and `BTreeMap`'s itertors are not `TrustedLen`, so this theoretically regressed perf for comparing large `BTreeMap`/`BTreeSet`s with unequal lengths but equal prefixes, (and also made it so that comparing two different-length `BTreeMap`/`BTreeSet`s with elements whose `PartialEq` impls that can panic now can panic, though this is not a "promised" behaviour either way (cc rust-lang/rust#149122))

Given that `TrustedLen` is an unsafe trait, I opted to not implement it for `BTreeMap`'s iterators, and instead just revert the change. If someone else wants to audit `BTreeMap`'s iterators to make sure they always return the right number of items (even in the face of incorrect user `Ord` impls) and then implement `TrustedLen` for them so that the optimization works for them, then this can be closed in favor of that (or if the perf regression is deemed too theoretical, this can be closed outright).

Example of theoretical perf regression: https://play.rust-lang.org/?version=beta&mode=release&edition=2024&gist=a37e3d61e6bf02669b251315c9a44fe2 (very rough estimates, using `Instant::elapsed`).
In release mode on stable the comparison takes ~23.68µs.
In release mode on beta/nightly the comparison takes ~48.351057ms.
2025-12-02 17:04:58 +00:00
Stuart Cook
dbb92adfc1
Rollup merge of #145628 - tinnamchoi:fix-btree-append, r=Amanieu
[std][BTree] Fix behavior of `::append` to match documentation, `::insert`, and `::extend`

Resolves rust-lang/rust#145614
2025-12-02 13:56:29 +11:00
bendn
d67f99af2e
fix 2025-11-27 17:55:34 +07:00
Matthias Krüger
cd4ce66e50
Rollup merge of #147035 - joboet:extract_if_debug, r=tgross35
alloc: fix `Debug` implementation of `ExtractIf`

I noticed this while reviewing rust-lang/rust#141032. Calling `get` on the inner `Vec` never returns `Some` as the `Vec`'s length is temporarily set to zero while the `ExtractIf` exists.
2025-11-20 11:15:50 +01:00
Zachary S
907f5c1180 Add regression test for collections' PartialEq::eq impls not comparing elements if lengths are different. 2025-11-20 00:15:02 -06:00
Pavel Grigorenko
f9dcc6b21c Stabilize char_max_len 2025-11-14 18:23:19 +03:00
joboet
47342cf971
alloc: remove test of unsound specialization behaviour 2025-11-09 17:31:19 +01:00
joboet
5fb5861765
(almost) get rid of the unsound #[rustc_unsafe_specialization_marker] on Copy, introduce TrivialClone 2025-11-09 15:51:25 +01:00
Jacob Pratt
4ad5a39183
Rollup merge of #147808 - hkBst:btree-3, r=joboet
btree: cleanup difference, intersection, is_subset
2025-11-07 00:21:19 -05:00
Jacob Pratt
47eeb00a63
Rollup merge of #145992 - GrigorenkoPV:stabilize/vec_deque_pop_if, r=Amanieu
Stabilize `vec_deque_pop_if`

Tracking issue: rust-lang/rust#135889
Closes rust-lang/rust#135889
Also fixes a typo mentioned in https://github.com/rust-lang/rust/issues/135889#issuecomment-2991213248

FCP: https://github.com/rust-lang/rust/issues/135889#issuecomment-3238777731

`@rustbot` label -T-libs +T-libs-api +needs-fcp +S-waiting-on-fcp

r? t-libs-api
2025-11-07 00:21:17 -05:00
Marijn Schouten
acd0294845 btree: cleanup difference, intersection, is_subset 2025-11-04 15:37:54 +00:00
Antoni Spaanderman
5b96677adb
add specialization for extend_front and prepend with copied slice iterator 2025-11-03 12:35:30 +01:00
Antoni Spaanderman
e23c1551a7
implement VecDeque extend_front and prepend, add tests 2025-11-01 18:30:01 +01:00
Matthias Krüger
53c52a2ae4
Rollup merge of #147161 - antonilol:vec-deque-extend-from-within, r=joboet
implement VecDeque extend_from_within and prepend_from_within

Tracking issue: rust-lang/rust#146975
2025-10-31 18:41:48 +01:00
Jacob Pratt
f1a0dfd145
Rollup merge of #138217 - theemathas:cow_is_owned_borrowed_associated, r=dtolnay
Turn `Cow::is_borrowed,is_owned` into associated functions.

This is done because `Cow` implements `Deref`. Therefore, to avoid conflicts with an inner type having a method of the same name, we use an associated method, like `Box::into_raw`.

Tracking issue: #65143
2025-10-30 02:43:41 -04:00
Pavel Grigorenko
2f4813fa0a Stabilize vec_deque_pop_if 2025-10-23 23:43:59 +03:00
Antoni Spaanderman
63bb238e5d
implement VecDeque extend_from_within and prepend_from_within, add tests 2025-10-23 13:52:55 +02:00
William Venner
8ed7fca74c Add String::replace_first and String::replace_last
Rebased and modified by zachs18.

Co-authored-by: zachs18 <8355914+zachs18@users.noreply.github.com>
2025-10-21 16:11:55 -05:00
Matthias Krüger
f104ae4252
Rollup merge of #145113 - petrochenkov:lessfinalize, r=lcnr
resolve: Do not finalize shadowed bindings

I.e. do not mark them as used, or non-speculatively loaded, or similar.
Previously they were sometimes finalized during early resolution, causing issues like https://github.com/rust-lang/rust/pull/144793#issuecomment-3168108005.
2025-09-26 18:11:08 +02:00
Vadim Petrochenkov
f89660e4aa resolve: Do not finalize shadowed bindings
I.e. do not mark them as used, or non-speculative loaded, or similar.
Previously they were sometimes finalized during early resolution, causing issues like https://github.com/rust-lang/rust/pull/144793#issuecomment-3168108005.
2025-09-25 20:36:14 +03:00
joboet
09097128c3
alloc: fix Debug implementation of ExtractIf 2025-09-25 17:48:08 +02:00