about summary refs log tree commit diff
path: root/library/alloc/src
AgeCommit message (Collapse)AuthorLines
2025-09-25Revert "Auto merge of #144086 - clubby789:alloc-zeroed, r=nikic"Nikita Popov-1/+0
This reverts commit 040a98af70f0a7da03f3d5356531b28a2a7a77e4, reversing changes made to e8a792daf500b5ff8097896ddb6cc037abe92487.
2025-09-14Update CURRENT_RUSTC_VERSION post-bumpMark Rousskov-13/+13
2025-09-13Rollup merge of #145471 - rs-sac:extr, r=the8472Jacob Pratt-12/+10
Stabilize BTree{Map,Set}::extract_if Tracking issue: rust-lang/rust#70530 FCP completed: https://github.com/rust-lang/rust/issues/70530#issuecomment-3191454465 Closes: rust-lang/rust#70530
2025-09-07optimization: Don't include ASCII characters in Unicode tablesKarl Meakin-3/+2
The ASCII subset of Unicode is fixed and will never change, so we don't need to generate tables for it with every new Unicode version. This saves a few bytes of static data and speeds up `char::is_control` and `char::is_grapheme_extended` on ASCII inputs. Since the table lookup functions exported from the `unicode` module will give nonsensical errors on ASCII input (and in fact will panic in debug mode), I had to add some private wrapper methods to `char` which check for ASCII-ness first.
2025-09-04Rollup merge of #145750 - btj:drop-alloc-guard, r=tgross35Stuart Cook-25/+2
raw_vec.rs: Remove superfluous fn alloc_guard `alloc_guard` checks that its argument is at most `isize::MAX`, but it is called only with layout sizes, which are already guaranteed to be at most `isize::MAX`.
2025-09-03Rollup merge of #145279 - clarfonthey:const-convert-initial, r=tgross35Stuart Cook-7/+17
Constify conversion traits (part 1) This is the first part of rust-lang/rust#144289 being split into smaller pieces. It adds/moves constness of several traits under the `const_convert` feature: * `From` * `Into` * `TryFrom` * `TryInto` * `FromStr` * `AsRef` * `AsMut` * `Borrow` * `BorrowMut` * `Deref` * `DerefMut` There are a few methods that are intrinsically tied to these traits which I've included in the feature. Particularly, those which are wrappers over `AsRef`: * `ByteStr::new` (unstable under `bstr` feature) * `OsStr::new` * `Path::new` Those which directly use `Into`: * `Result::into_ok` * `Result::into_err` And those which use `Deref` and `DerefMut`: * `Pin::as_ref` * `Pin::as_mut` * `Pin::as_deref_mut` * `Option::as_deref` * `Option::as_deref_mut` * `Result::as_deref` * `Result::as_deref_mut` (note: the `Option` and `Result` methods were suggested by ``@npmccallum`` initially as rust-lang/rust#146101) The parts which are missing from this PR are: * Anything that involves heap-allocated types * Making any method const than the ones listed above * Anything that could rely on the above, *or* could rely on system-specific code for `OsStr` or `Path` (note: this mostly makes these methods useless since `str` doesn't implement `AsRef<OsStr>` yet, but it's better to track the method for now and add impls later, IMHO) r? ``@tgross35`` (who mostly already reviewed this)
2025-09-03raw_vec.rs: Remove superfluous fn alloc_guardBart Jacobs-25/+2
It checks that its argument is at most isize::MAX, but it is called only with layout sizes, which are already guaranteed to be at most isize::MAX.
2025-09-01Constify conversion traitsltdk-7/+17
2025-08-31Rollup merge of #145592 - nilotpal-n7:fix-format-alignment, r=lcnrMatthias Krüger-1/+1
Fix format string grammar in docs and improve alignment error message for #144023 This PR improves error messages and documentation for format strings involving alignment and formatting traits. Highlights: - Clearer error messages for invalid alignment specifiers (e.g., `{0:#X>18}`), showing the expected `<`, `^`, or `>` and a working example: println!("{0:>#18X}", value); - Updated UI test `format-alignment-hash.rs` to reflect the improved error output. - Documentation clarification: ensures examples correctly show how width, alignment, and traits like `x`, `X`, `#` combine. Motivation: Previously, using `#` with alignment and width produced confusing errors. This PR guides users on the correct syntax and provides actionable examples. Testing: - Built the compiler (`./x build`) - Blessed and ran UI tests (`./x. test src/test/ui/fmt/format-alignment-hash.rs --bless`) - Verified full test suite passes (`./x test`) Issue: rust-lang/rust#144023
2025-08-27Stabilize BTree{Map,Set}::extract_ifSidney Cammeresi-12/+10
2025-08-27Fix format string grammar in docs and improve alignment error messageNilotpal Gupta-1/+1
2025-08-27Rollup merge of #145562 - tbu-:pr_simplify_to_string_spec, r=tgross35Matthias Krüger-50/+23
Simplify macro generating ToString implementations for `&…&str` Use deref coercion to let the compiler remove any amount of references. Also use that macro for `Cow` and `String`.
2025-08-27Rollup merge of #145335 - clarfonthey:wtf8-core-alloc, r=Mark-SimulacrumMatthias Krüger-0/+1297
Move WTF-8 code from std into core and alloc This is basically a small portion of rust-lang/rust#129411 with a smaller scope. It *does not*\* affect any public APIs; this code is still internal to the standard library. It just moves the WTF-8 code into `core` and `alloc` so it can be accessed by `no_std` crates like `backtrace`. > \* The only public API this affects is by adding a `Debug` implementation to `std::os::windows::ffi::EncodeWide`, which was not present before. This is due to the fact that `core` requires `Debug` implementations for all types, but `std` does not (yet) require this. Even though this was ultimately changed to be a wrapper over the original type, not a re-export, I decided to keep the `Debug` implementation so it remains useful. Like we do with ordinary strings, the tests are still located entirely in `alloc`, rather than splitting them into `core` and `alloc`. ---- Reviewer note: for ease of review, this is split into three commits: 1. Moving the original files into their new "locations" 2. Actually modifying the code to compile. 3. Removing aesthetic changes that were made so that the diff for commit 2 was readable. You can review commits 1 and 3 to verify these claims, but commit 2 contains the majority of the changes you should care about. ---- API changes: `impl Debug for std::os::windows::ffi::EncodeWide`
2025-08-26Fix typo in commentTobias Stoeckmann-1/+1
Turn "any heap allocators" into "any heap allocator".
2025-08-26Rollup merge of #144373 - hkBst:remove-deprecated-1, r=jhprattGuillaume Gomez-51/+5
remove deprecated Error::description in impls [libs-api permission](https://github.com/rust-lang/libs-team/issues/615#issuecomment-3074045829) r? `@cuviper` or `@jhpratt`
2025-08-26remove deprecated Error::description in implsMarijn Schouten-51/+5
2025-08-24Prevent confusion with insertion-ordered maps.Marijn Schouten-2/+3
2025-08-24focus more on ordered aspect and restore old commentsMarijn Schouten-13/+45
2025-08-24Dial down detail of B-tree descriptionMarijn Schouten-24/+5
fixes 134088, though it is a shame to lose some of this wonderful detail.
2025-08-20Diff-massaging commitltdk-41/+34
2025-08-20Move WTF-8 code from std to core/allocltdk-708/+178
2025-08-20Copy WTF-8 code into core/alloc (for better diffs)ltdk-0/+1834
2025-08-20Auto merge of #144086 - clubby789:alloc-zeroed, r=nikicbors-0/+1
Pass `alloc-variant-zeroed` to LLVM Makes use of https://github.com/llvm/llvm-project/pull/138299 (once we pull in a version of LLVM with this attribute). ~~Unfortunately also requires https://github.com/llvm/llvm-project/pull/149336 to work.~~ Closes rust-lang/rust#104847
2025-08-20Pass `alloc-variant-zeroed` to LLVMclubby789-0/+1
2025-08-19Use `ToString` specialization macro also for `Cow` and `String`Tobias Bucher-16/+2
2025-08-19Simplify macro generating `ToString` implementations for `&…&str`Tobias Bucher-34/+21
Use deref coercion to let the compiler remove any amount of references.
2025-08-15Rollup merge of #143717 - Jules-Bertholet:pin-default, r=dtolnayJacob Pratt-4/+44
Add `Default` impls for `Pin`ned `Box`, `Rc`, `Arc` Fixes rust-lang/rust#143688. `@rustbot` label T-libs-api needs-fcp Also needs a crater run, as the `Box` impls could theoretically be breaking due to `#[fundamental]` (though a [cursory search](https://github.com/search?q=%2Fimpl%28%3C.*%3E%29%3F+Default+for+Pin%3C%2F+path%3A*.rs&type=code) suggests this is unlikely to cause issues).
2025-08-12Add cast_init and cast_uninit methods for pointersltdk-1/+2
2025-08-12Handle the `capacity == 0` caseSabrinaJewson-27/+34
2025-08-11Respond to review commentsSabrinaJewson-5/+5
2025-08-11Make explicit guarantees about `Vec`’s allocatorSabrinaJewson-4/+47
This commit amends the documentation of `Vec::as_mut_ptr` and `Vec::into_raw_parts` to make it explicit that such calls may be paired with calls to `dealloc` with a suitable layout. This guarantee was effectively already provided by the docs of `Vec::from_raw_parts` mentioning `alloc`. Additionally, we copy-paste and adjust the “Memory layout” section from the documentation of `std::boxed` to `std::vec`. This explains the allocator guarantees in more detail.
2025-08-09`{BTree,Hash}Map`: add "`Entry` API" section headingAda Alakbarova-0/+2
2025-08-07Auto merge of #144997 - BoxyUwU:bootstrap_bump, r=Mark-Simulacrumbors-8/+8
bump bootstrap compiler to 1.90 beta There were significantly less `cfg(bootstrap)` and `cfg(not(bootstrap))` this release. Presumably due to the fact that we change the bootstrap stage orderings to reduce the need for them and it was successful :pray:
2025-08-06replace version placeholderBoxy-8/+8
2025-08-04Correct the use of `must_use` on btree::IterMutJonathan Brouwer-1/+1
Signed-off-by: Jonathan Brouwer <jonathantbrouwer@gmail.com>
2025-08-02Rollup merge of #144478 - joshtriplett:doc-code-formatting-prep, r=AmanieuSamuel Tardieu-7/+7
Improve formatting of doc code blocks We don't currently apply automatic formatting to doc comment code blocks. As a result, it has built up various idiosyncracies, which make such automatic formatting difficult. Some of those idiosyncracies also make things harder for human readers or other tools. This PR makes a few improvements to doc code formatting, in the hopes of making future automatic formatting easier, as well as in many cases providing net readability improvements. I would suggest reading each commit separately, as each commit contains one class of changes.
2025-07-31Rollup merge of #135975 - balt-dev:master, r=tgross35Stuart Cook-29/+243
Implement `push_mut` Implementation of rust-lang/rust#135974.
2025-07-30Implement push_mutBalt-29/+243
2025-07-27Remove `[T]::array_chunks(_mut)`Scott McMurray-17/+12
2025-07-25Avoid placing `// FIXME` comments inside doc code blocksJosh Triplett-6/+6
This leads tools like rustfmt to get confused, because the doc code block effectively spans two doc comments. As a result, the tools think the first code block is unclosed, and the subsequent terminator opens a new block. Move the FIXME comments outside the doc code blocks, instead.
2025-07-25Improve and regularize comment placement in doc codeJosh Triplett-1/+1
Because doc code does not get automatically formatted, some doc code has creative placements of comments that automatic formatting can't handle. Reformat those comments to make the resulting code support standard Rust formatting without breaking; this is generally an improvement to readability as well. Some comments are not indented to the prevailing indent, and are instead aligned under some bit of code. Indent them to the prevailing indent, and put spaces *inside* the comments to align them with code. Some comments span several lines of code (which aren't the line the comment is about) and expect alignment. Reformat them into one comment not broken up by unrelated intervening code. Some comments are placed on the same line as an opening brace, placing them effectively inside the subsequent block, such that formatting would typically format them like a line of that block. Move those comments to attach them to what they apply to. Some comments are placed on the same line as a one-line braced block, effectively attaching them to the closing brace, even though they're about the code inside the block. Reformat to make sure the comment will stay on the same line as the code it's commenting.
2025-07-22Rename `tests/codegen` into `tests/codegen-llvm`Guillaume Gomez-2/+2
2025-07-18Rollup merge of #143909 - nik-rev:patch-1, r=jhprattMatthias Krüger-2/+2
docs(alloc::fmt): Make type optional, instead of matching empty string Think this is clearer. Noticed as I was implementing [`tree-sitter-rust-format-args`](https://github.com/nik-rev/tree-sitter-rust-format-args), and attempting to match the empty string results in an error.
2025-07-17Rollup merge of #143595 - fee1-dead-contrib:push-sylpykzkmynr, ↵León Orell Valerian Liehr-3/+4
r=RalfJung,fee1-dead add `const_make_global`; err for `const_allocate` ptrs if didn't call Implements as discussed on Zulip: [#t-compiler/const-eval > const heap](https://rust-lang.zulipchat.com/#narrow/channel/146212-t-compiler.2Fconst-eval/topic/const.20heap/with/527125421) r? ```@rust-lang/wg-const-eval``` Fixes https://github.com/rust-lang/rust/issues/129233
2025-07-15Add `Default` impls for `Pin`ned `Box`, `Rc`, `Arc`Jules Bertholet-4/+44
2025-07-16add `const_make_global`; err for `const_allocate` ptrs if didn't callDeadbeef-3/+4
Co-Authored-By: Ralf Jung <post@ralfj.de> Co-Authored-By: Oli Scherer <github333195615777966@oli-obk.de>
2025-07-15Auto merge of #143877 - xizheyin:143813, r=scottmcm,saethlinbors-3/+18
`std::vec`: Add UB check for `set_len`, `from_raw_parts_in`, and etc. Closes rust-lang/rust#143813 I noticed that `from_parts_in` do the similar things like `from_raw_parts_in`, so I add the UB check in the last commit. If it is not appropriate, I will remove it. And I fix a typo in the first commit. r? `@scottmcm`
2025-07-13docs(alloc::fmt): Make `type` optional, instead of matching the empty stringNik Revenco-2/+2
2025-07-13update issue number for `const_trait_impl`Deadbeef-2/+2
2025-07-13std::vec: Add UB check in `from_parts_in`xizheyin-0/+5
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>