3355 Commits

Author SHA1 Message Date
Jacob Pratt
5b37a1e4ae
Rollup merge of #145471 - rs-sac:extr, r=the8472
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-13 03:26:02 -04:00
Karl Meakin
a8c669461f optimization: Don't include ASCII characters in Unicode tables
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-07 15:21:24 +02:00
Stuart Cook
d71a9b6bcf
Rollup merge of #145750 - btj:drop-alloc-guard, r=tgross35
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-04 10:01:53 +10:00
Stuart Cook
f4b946a147
Rollup merge of #145279 - clarfonthey:const-convert-initial, r=tgross35
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-03 23:08:06 +10:00
Bart Jacobs
d9dc20c752 raw_vec.rs: Remove superfluous fn alloc_guard
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-03 07:34:32 +02:00
ltdk
1c64d3e6d1 Constify conversion traits 2025-09-01 21:38:26 -04:00
Matthias Krüger
e5f96e3b43
Rollup merge of #145592 - nilotpal-n7:fix-format-alignment, r=lcnr
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-31 13:40:35 +02:00
Sidney Cammeresi
f8a7f82bda Stabilize BTree{Map,Set}::extract_if 2025-08-27 11:34:31 -07:00
Nilotpal Gupta
fdbaaac245 Fix format string grammar in docs and improve alignment error message 2025-08-27 20:45:41 +05:30
Matthias Krüger
f2eb47a81b
Rollup merge of #145562 - tbu-:pr_simplify_to_string_spec, r=tgross35
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-27 11:26:49 +02:00
Matthias Krüger
62e5341661
Rollup merge of #145335 - clarfonthey:wtf8-core-alloc, r=Mark-Simulacrum
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-27 07:45:56 +02:00
Tobias Stoeckmann
45296bb633 Fix typo in comment
Turn "any heap allocators" into "any heap allocator".
2025-08-26 22:58:44 +02:00
Guillaume Gomez
9bb7d17d9a
Rollup merge of #144373 - hkBst:remove-deprecated-1, r=jhpratt
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-26 16:34:09 +02:00
Marijn Schouten
845311a065 remove deprecated Error::description in impls 2025-08-26 06:36:53 +00:00
Marijn Schouten
1b77387085 Prevent confusion with insertion-ordered maps. 2025-08-24 10:50:20 +00:00
Marijn Schouten
bb7993f807 focus more on ordered aspect and restore old comments 2025-08-24 10:50:20 +00:00
Marijn Schouten
3f339ab849 Dial down detail of B-tree description
fixes 134088, though it is a shame to lose some of this wonderful detail.
2025-08-24 10:50:20 +00:00
ltdk
7c81a067ea Diff-massaging commit 2025-08-20 20:31:33 -04:00
ltdk
2914291e09 Move WTF-8 code from std to core/alloc 2025-08-20 20:31:33 -04:00
ltdk
5a2fceefd3 Copy WTF-8 code into core/alloc (for better diffs) 2025-08-20 20:31:33 -04:00
bors
040a98af70 Auto merge of #144086 - clubby789:alloc-zeroed, r=nikic
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-20 17:16:34 +00:00
clubby789
8ea3b09381 Pass alloc-variant-zeroed to LLVM 2025-08-20 17:08:46 +01:00
Tobias Bucher
cb5a4d138a Use ToString specialization macro also for Cow and String 2025-08-19 17:35:56 +02:00
Tobias Bucher
6a24ae96ea Simplify macro generating ToString implementations for &…&str
Use deref coercion to let the compiler remove any amount of references.
2025-08-19 17:35:55 +02:00
Jacob Pratt
41e40f3630
Rollup merge of #143717 - Jules-Bertholet:pin-default, r=dtolnay
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-15 18:13:26 -04:00
ltdk
d6945f6d8c Add cast_init and cast_uninit methods for pointers 2025-08-12 16:57:56 -04:00
SabrinaJewson
1ce4b370e4
Handle the capacity == 0 case 2025-08-12 05:12:34 +01:00
SabrinaJewson
45e2449b2a
Respond to review comments 2025-08-11 19:02:00 +01:00
SabrinaJewson
19df24b3b8
Make explicit guarantees about Vec’s allocator
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-11 17:15:53 +01:00
Ada Alakbarova
c0a3e4802a
{BTree,Hash}Map: add "Entry API" section heading 2025-08-09 19:41:32 +02:00
bors
cd434309ef Auto merge of #144997 - BoxyUwU:bootstrap_bump, r=Mark-Simulacrum
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 🙏
2025-08-07 10:56:05 +00:00
Boxy
9ccc9f177e replace version placeholder 2025-08-06 13:22:38 +01:00
Jonathan Brouwer
b3317dd055
Correct the use of must_use on btree::IterMut
Signed-off-by: Jonathan Brouwer <jonathantbrouwer@gmail.com>
2025-08-04 22:20:30 +02:00
Samuel Tardieu
d082ff4c04
Rollup merge of #144478 - joshtriplett:doc-code-formatting-prep, r=Amanieu
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-08-02 11:24:24 +02:00
Stuart Cook
dc8aec4cf2
Rollup merge of #135975 - balt-dev:master, r=tgross35
Implement `push_mut`

Implementation of rust-lang/rust#135974.
2025-07-31 15:41:58 +10:00
Balt
3ccfa14e48 Implement push_mut 2025-07-30 12:26:16 -05:00
Scott McMurray
173926da2b Remove [T]::array_chunks(_mut) 2025-07-27 23:03:07 -07:00
Josh Triplett
b6c54a97b3 Avoid placing // FIXME comments inside doc code blocks
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-25 22:02:09 -07:00
Josh Triplett
715088094c Improve and regularize comment placement in doc code
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-25 22:02:09 -07:00
Trevor Gross
51c5f191de Remove compiler-builtins-mangled-names
This config was added in 207de019dc67 ("libary: Forward
compiler-builtins "asm"  and "mangled-names" feature") but it does not
appear this has ever been used. The PR adding it (RUST-78472) says that
this was exposed to help with configuration and points at the [Hermit
Cargo config], but as far as I can tell, this feature name has never
been mentioned in that repository's git history.

Thus, clean up a seemingly unneeded feature.

[Hermit Cargo config]: ab2b830930/.cargo/config
2025-07-25 19:21:20 -05:00
Trevor Gross
a076bd8a61 Remove compiler-builtins-no-asm
This feature used to be for when Cranelift didn't support inline
assembly, but its last uses were removed in 52933e0bd200 ("Don't disable
inline asm usage in compiler-builtins when the cranelift backend is
enabled"). and cba05a7a14b3 ("Support naked functions").

This doesn't remove the feature from the `compiler-builtins` crate, that
will be done separately in the subtree repo.
2025-07-25 17:08:57 -05:00
Guillaume Gomez
a27f3e3fd1 Rename tests/codegen into tests/codegen-llvm 2025-07-22 14:28:48 +02:00
Matthias Krüger
744ca5959a
Rollup merge of #143909 - nik-rev:patch-1, r=jhpratt
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-18 14:49:19 +02:00
León Orell Valerian Liehr
83288db888
Rollup merge of #143595 - fee1-dead-contrib:push-sylpykzkmynr, 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-17 03:58:30 +02:00
Jules Bertholet
87dd4695fe
Add Default impls for Pinned Box, Rc, Arc 2025-07-15 17:41:31 -04:00
Deadbeef
3f2dc2bd1a add const_make_global; err for const_allocate ptrs if didn't call
Co-Authored-By: Ralf Jung <post@ralfj.de>
Co-Authored-By: Oli Scherer <github333195615777966@oli-obk.de>
2025-07-16 00:32:12 +08:00
bors
3014e79f9c Auto merge of #143877 - xizheyin:143813, r=scottmcm,saethlin
`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-15 14:47:10 +00:00
Nik Revenco
f5485e5564
docs(alloc::fmt): Make type optional, instead of matching the empty string 2025-07-13 23:24:27 +01:00
Deadbeef
6b02597ed3 update issue number for const_trait_impl 2025-07-13 23:55:06 +08:00
xizheyin
48caa5f889
std::vec: Add UB check in from_parts_in
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-07-13 16:18:56 +08:00