summary refs log tree commit diff
path: root/library/alloc/src
AgeCommit message (Collapse)AuthorLines
2025-06-22Auto merge of #142728 - kornelski:string-track, r=tgross35bors-0/+23
Let String pass #[track_caller] to its Vec calls I've added `#[track_caller]` to `String` methods that delegate to `Vec` methods that already have `#[track_caller]`. I've also added `#[track_caller]` to methods that have `assert!` or `panic!` due to invalid inputs.
2025-06-20Rollup merge of #142764 - ChaiTRex:ilog_10_to_ilog10, r=workingjubileeJakub Beránek-2/+2
Convert `ilog(10)` to `ilog10()` Except in tests, convert `integer.ilog(10)` to `integer.ilog10()` for better speed and to provide better examples of code that efficiently counts decimal digits. I couldn't find any instances of `integer.ilog(2)`.
2025-06-20Convert `ilog(10)` to `ilog10()`Chai T. Rex-2/+2
2025-06-20Rollup merge of #142668 - hkBst:less-static-mut, r=tgross35Trevor Gross-43/+13
vec_deque/fmt/vec tests: remove static mut More rust-lang/rust#125035. r? ```@tgross35```
2025-06-20Auto merge of #142294 - GuillaumeGomez:specialize-tostring-on-128-integers, ↵bors-0/+1
r=tgross35 Use a distinct `ToString` implementation for `u128` and `i128` Part of https://github.com/rust-lang/rust/issues/135543. Follow-up of rust-lang/rust#136264. When working on https://github.com/rust-lang/rust/pull/142098, I realized that `i128` and `u128` could also benefit from a distinct `ToString` implementation so here it. The last commit is just me realizing that I forgot to add the format tests for `usize` and `isize`. Here is the bench comparison: | bench name | last nightly | with this PR | diff | |-|-|-|-| | bench_i128 | 29.25 ns/iter (+/- 0.66) | 17.52 ns/iter (+/- 0.7) | -40.1% | | bench_u128 | 34.06 ns/iter (+/- 0.21) | 16.1 ns/iter (+/- 0.6) | -52.7% | I used this code to test: ```rust #![feature(test)] extern crate test; use test::{Bencher, black_box}; #[inline(always)] fn convert_to_string<T: ToString>(n: T) -> String { n.to_string() } macro_rules! decl_benches { ($($name:ident: $ty:ident,)+) => { $( #[bench] fn $name(c: &mut Bencher) { c.iter(|| convert_to_string(black_box({ let nb: $ty = 20; nb }))); } )+ } } decl_benches! { bench_u128: u128, bench_i128: i128, } ```
2025-06-19Add #[track_caller] to String methods that assert inputsKornel-0/+6
2025-06-19Let String pass #[track_caller] to its Vec callsKornel-0/+17
2025-06-18vec_deque tests: remove static mutMarijn Schouten-43/+13
2025-06-18Auto merge of #141061 - dpaoliello:shimasfn, r=bjorn3bors-3/+4
Change __rust_no_alloc_shim_is_unstable to be a function This fixes a long sequence of issues: 1. A customer reported that building for Arm64EC was broken: #138541 2. This was caused by a bug in my original implementation of Arm64EC support, namely that only functions on Arm64EC need to be decorated with `#` but Rust was decorating statics as well. 3. Once I corrected Rust to only decorate functions, I started linking failures where the linker couldn't find statics exported by dylib dependencies. This was caused by the compiler not marking exported statics in the generated DEF file with `DATA`, thus they were being exported as functions not data. 4. Once I corrected the way that the DEF files were being emitted, the linker started failing saying that it couldn't find `__rust_no_alloc_shim_is_unstable`. This is because the MSVC linker requires the declarations of statics imported from other dylibs to be marked with `dllimport` (whereas it will happily link to functions imported from other dylibs whether they are marked `dllimport` or not). 5. I then made a change to ensure that `__rust_no_alloc_shim_is_unstable` was marked as `dllimport`, but the MSVC linker started emitting warnings that `__rust_no_alloc_shim_is_unstable` was marked as `dllimport` but was declared in an obj file. This is a harmless warning which is a performance hint: anything that's marked `dllimport` must be indirected via an `__imp` symbol so I added a linker arg in the target to suppress the warning. 6. A customer then reported a similar warning when using `lld-link` (<https://github.com/rust-lang/rust/pull/140176#issuecomment-2872448443>). I don't think it was an implementation difference between the two linkers but rather that, depending on the obj that the declaration versus uses of `__rust_no_alloc_shim_is_unstable` landed in we would get different warnings, so I suppressed that warning as well: #140954. 7. Another customer reported that they weren't using the Rust compiler to invoke the linker, thus these warnings were breaking their build: <https://github.com/rust-lang/rust/pull/140176#issuecomment-2881867433>. At that point, my original change was reverted (#141024) leaving Arm64EC broken yet again. Taking a step back, a lot of these linker issues arise from the fact that `__rust_no_alloc_shim_is_unstable` is marked as `extern "Rust"` in the standard library and, therefore, assumed to be a foreign item from a different crate BUT the Rust compiler may choose to generate it either in the current crate, some other crate that will be statically linked in OR some other crate that will by dynamically imported. Worse yet, it is impossible while building a given crate to know if `__rust_no_alloc_shim_is_unstable` will statically linked or dynamically imported: it might be that one of its dependent crates is the one with an allocator kind set and thus that crate (which is compiled later) will decide depending if it has any dylib dependencies or not to import `__rust_no_alloc_shim_is_unstable` or generate it. Thus, there is no way to know if the declaration of `__rust_no_alloc_shim_is_unstable` should be marked with `dllimport` or not. There is a simple fix for all this: there is no reason `__rust_no_alloc_shim_is_unstable` must be a static. It needs to be some symbol that must be linked in; thus, it could easily be a function instead. As a function, there is no need to mark it as `dllimport` when dynamically imported which avoids the entire mess above. There may be a perf hit for changing the `volatile load` to be a `tail call`, so I'm happy to change that part back (although I question what the codegen of a `volatile load` would look like, and if the backend is going to try to use load-acquire semantics). Build with this change applied BEFORE #140176 was reverted to demonstrate that there are no linking issues with either MSVC or MinGW: <https://github.com/rust-lang/rust/actions/runs/15078657205> Incidentally, I fixed `tests/run-make/no-alloc-shim` to work with MSVC as I needed it to be able to test locally (FYI for #128602) r? `@bjorn3` cc `@jieyouxu`
2025-06-17Rollup merge of #142520 - hkBst:less-static-mut, r=tgross35Jacob Pratt-106/+55
alloc: less static mut + some cleanup I'm looking into https://github.com/rust-lang/rust/issues/125035 and would like some feedback on my approach.
2025-06-17Rollup merge of #138538 - hkBst:patch-4, r=tgross35Jubilee-9/+16
Make performance description of String::{insert,insert_str,remove} more precise
2025-06-17linked_list tests: buff check_linksMarijn Schouten-40/+25
2025-06-17Make performance of String::insert_str more preciseMarijn Schouten-9/+16
2025-06-16Change __rust_no_alloc_shim_is_unstable to be a functionDaniel Paoliello-3/+4
2025-06-16Specialize `ToString` implementation on `u128` and `i128`Guillaume Gomez-0/+1
2025-06-16linked_list tests: less static mutMarijn Schouten-66/+30
2025-06-14Rollup merge of #142484 - dtolnay:bsetextract, r=m-ou-seMatthias Krüger-4/+4
Remove unneeded lifetime bound from signature of BTreeSet::extract_if One way to observe the difference between these signatures, using 0 explicit lifetimes and 0 contrived where-clauses: ```rust use std::collections::btree_set::{BTreeSet, ExtractIf}; use std::ops::RangeFull; fn repro( set: &mut BTreeSet<i32>, predicate: impl Fn(i32) -> bool, ) -> ExtractIf<i32, RangeFull, impl FnMut(&i32) -> bool> { set.extract_if(.., move |x| predicate(*x)) } ``` **Before:** ```console error[E0311]: the parameter type `impl Fn(i32) -> bool` may not live long enough --> src/lib.rs:8:5 | 5 | set: &mut BTreeSet<i32>, | ------------------ the parameter type `impl Fn(i32) -> bool` must be valid for the anonymous lifetime defined here... ... 8 | set.extract_if(.., move |x| predicate(*x)) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ...so that the type `impl Fn(i32) -> bool` will meet its required lifetime bounds | help: consider adding an explicit lifetime bound | 4 ~ fn repro<'a>( 5 ~ set: &'a mut BTreeSet<i32>, 6 ~ predicate: impl Fn(i32) -> bool + 'a, 7 ~ ) -> ExtractIf<'a, i32, RangeFull, impl FnMut(&i32) -> bool> { | ``` **After:** compiles success. - Tracking issue: https://github.com/rust-lang/rust/issues/70530
2025-06-13Rollup merge of #142046 - Qelxiros:122742-vec_peek_mut, r=cuviperJubilee-0/+87
add Vec::peek_mut Tracking issue: rust-lang/rust#122742
2025-06-13Remove unneeded lifetimes from signature of BTreeSet::extract_ifDavid Tolnay-4/+4
2025-06-12Delegate `<CStr as Debug>` to `ByteStr`Tamir Duberstein-0/+2
This allows UTF-8 characters to be printed without escapes, rather than just ASCII.
2025-06-11update docs, testJeremy Smart-5/+1
2025-06-09stabilize nonnull_provenanceRalf Jung-1/+0
2025-06-06fix testsJeremy Smart-0/+1
2025-06-06remove extraneous textTshepang Mbambo-6/+0
"Basic usage" implies there is an example that shows advanced usage
2025-06-04add Vec::peek_mutJeremy Smart-0/+90
2025-06-04Rollup merge of #141924 - rs-sac:extr-doc, r=jhprattMatthias Krüger-7/+7
Lightly tweak docs for BTree{Map,Set}::extract_if - Move explanations into comments to match style - Explain the second examples - Make variable names match the data structure Related rust-lang/rust#70530
2025-06-02Remove more library bootstrapJosh Stone-1/+0
2025-06-02Lightly tweak docs for BTree{Map,Set}::extract_ifSidney Cammeresi-7/+7
- Move explanations into comments to match style - Explain the second examples - Make variable names match the data structure
2025-05-27Unit test for Range parameter of `BTreeMap::extract_if`Sidney Cammeresi-0/+24
2025-05-27Update docs for new Range parameter to `BTreeMap::extract_if` etc.Sidney Cammeresi-4/+16
2025-05-27Update tests with Range parameter to `BTreeMap::extract_if` etc.Sidney Cammeresi-31/+31
2025-05-27Add Range parameter to `BTreeMap::extract_if` and `BTreeSet::extract_if`Sidney Cammeresi-19/+57
This change was requested in the btree_extract_if tracking issue: https://github.com/rust-lang/rust/issues/70530#issuecomment-2486566328
2025-05-25Rollup merge of #141108 - PaulDance:fix-extract_if-docs, r=Mark-SimulacrumJacob Pratt-17/+19
Docs(lib): Fix `extract_if` docs Various fixes to the documentation comments of the several `extract_if` collection methods available. It originally started with a small typo fix in `Vec`'s spotted when reading the 1.87 release notes, but then by looking at the others' for comparison in order to try determining what was the intended sentence, some inconsistencies were spotted. Therefore, some other changes are also proposed here to reduce these avoidable differences, going more and more nit-picky along the way. See the individual commits for more details about each change. `@rustbot` label T-libs A-collections A-docs
2025-05-22Rollup merge of #141370 - WaffleLapkin:hiiii, r=jhprattMatthias Krüger-0/+1
add doc alias `replace_first` for `str::replacen` `replace_first` is a sensible name for a function, analogous to actually existing `<[_]>::split_first`, for example. (I just saw someone try to search for it) I think it's reasonable to add such an alias for `replacen`, which replaces the first occurrence of passed a 1.
2025-05-21add doc alias `replace_first` for `str::replacen`waffle-0/+1
2025-05-21Rollup merge of #141230 - xizheyin:issue-141217, r=tgross35Matthias Krüger-5/+28
std: fix doctest and explain for `as_slices` and `as_mut_slices` in `VecDeque` Fixes #141217 r? libs
2025-05-21Rollup merge of #140526 - Natr1x:sort-direction-documentation, r=dtolnayMatthias Krüger-4/+7
docs: Specify that common sort functions sort in an ascending direction From [forum discussion](https://users.rust-lang.org/t/is-there-a-way-to-sort-a-slice-in-specifically-ascending-or-descending-order/128998?u=natr1x) it seems like the sorting direction can be expected to always be ascending (in terms of `cmp::Ordering`). If this is the case then it would be nice to have this stated in the documentation.
2025-05-21std: fix doctest and explain for as_slices and as_mut_slices in VecDequexizheyin-5/+28
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-05-20Rollup merge of #141289 - compiler-errors:more-self, r=jhprattMatthias Krüger-2/+2
use `Self` alias in self types rather than manually substituting it Of the rougly 145 uses of `self: Ty` in the standard library, 5 of them don't use `Self` but instead choose to manually "substitute" the `impl`'s self type into the type. This leads to weird behavior sometimes (https://github.com/rust-lang/rust/issues/140611#issuecomment-2883761300) -- **to be clear**, none of these usages actually trigger any bugs, but it's possible that they may break in the future (or at least lead to lints), so let's just "fix" them proactively.
2025-05-20use Self alias in self types rather than manually substituting itMichael Goulet-2/+2
2025-05-17Docs(lib/extract_if): Unify example descriptionPaul Mabileau-2/+2
Signed-off-by: Paul Mabileau <paul.mabileau@harfanglab.fr>
2025-05-17Docs(lib/extract_if): Unify paragraph about elements mutationPaul Mabileau-4/+4
Take the one from `BTreeMap` that seems the best-worded and most precise among the available variations. Signed-off-by: Paul Mabileau <paul.mabileau@harfanglab.fr>
2025-05-17Docs(lib/extract_if): Unify paragraph about closure actionsPaul Mabileau-6/+6
Also fixes `HashSet`'s that incorrectly designated itself as a `list`. Signed-off-by: Paul Mabileau <paul.mabileau@harfanglab.fr>
2025-05-17Docs(lib/coll/btm): Split `extract_if`'s first sentence from the following onesPaul Mabileau-4/+6
This also seems like a small mistake: the first main sentence is put in the same paragraph as the other two following ones while other equivalents all have it split. Therefore, do the same here. Signed-off-by: Paul Mabileau <paul.mabileau@harfanglab.fr>
2025-05-17Docs(lib/alloc/vec): Add the missing `an` to `extract_if`'s first sentencePaul Mabileau-1/+1
As inspired by the equivalent methods from other collection types. Signed-off-by: Paul Mabileau <paul.mabileau@harfanglab.fr>
2025-05-15Auto merge of #141050 - matthiaskrgr:rollup-uyzqbmj, r=matthiaskrgrbors-4/+4
Rollup of 7 pull requests Successful merges: - #139749 (docs(library/core/src/pin): fix typo "necessarily" -> "necessary") - #140685 (Simplify `Vec::as_non_null` implementation and make it `const`) - #140712 (normalization: avoid incompletely constraining GAT args) - #140768 (Improve `dangerous_implicit_aurorefs` diagnostic output) - #140947 (Flush errors before deep normalize in `dropck_outlives`) - #140990 (VxWorks: updates from recent libc versions) - #141027 (remove `RustfmtState` to reduce `initial_rustfmt` complexity) r? `@ghost` `@rustbot` modify labels: rollup
2025-05-15Rollup merge of #140685 - viliml:patch-1, r=Mark-SimulacrumMatthias Krüger-4/+4
Simplify `Vec::as_non_null` implementation and make it `const` Tracking issue: #130364.
2025-05-15Auto merge of #136264 - GuillaumeGomez:optimize-integers-to-string, r=Amanieubors-0/+48
Optimize `ToString` implementation for integers Part of https://github.com/rust-lang/rust/issues/135543. Follow-up of https://github.com/rust-lang/rust/pull/133247 and https://github.com/rust-lang/rust/pull/128204. The benchmark results are: | name| 1.87.0-nightly (3ea711f17 2025-03-09) | With this PR | diff | |-|-|-|-| | bench_i16 | 32.06 ns/iter (+/- 0.12) | 17.62 ns/iter (+/- 0.03) | -45% | | bench_i32 | 31.61 ns/iter (+/- 0.04) | 15.10 ns/iter (+/- 0.06) | -52% | | bench_i64 | 31.71 ns/iter (+/- 0.07) | 15.02 ns/iter (+/- 0.20) | -52% | | bench_i8 | 13.21 ns/iter (+/- 0.14) | 14.93 ns/iter (+/- 0.16) | +13% | | bench_u16 | 31.20 ns/iter (+/- 0.06) | 16.14 ns/iter (+/- 0.11) | -48% | | bench_u32 | 33.27 ns/iter (+/- 0.05) | 16.18 ns/iter (+/- 0.10) | -51% | | bench_u64 | 31.44 ns/iter (+/- 0.06) | 16.62 ns/iter (+/- 0.21) | -47% | | bench_u8 | 10.57 ns/iter (+/- 0.30) | 13.00 ns/iter (+/- 0.43) | +22% | More information about it in [the original comment](https://github.com/rust-lang/rust/pull/136264#discussion_r1987542954). r? `@workingjubilee`
2025-05-12update cfg(bootstrap)Pietro Albini-2/+2
2025-05-12update version placeholdersPietro Albini-1/+1