Commit Graph

3673 Commits

Author SHA1 Message Date
Matthias Krüger 27282040f7 Rollup merge of #155705 - Jules-Bertholet:word-to-titlecase, r=Mark-Simulacrum
Add `str::word_to_titlecase()` to `alloc`

A small addition to https://github.com/rust-lang/rust/issues/153892.

Hasn't gone through ACP, so needs libs-API signoff.

@rustbot label A-Unicode T-libs-api
2026-05-10 03:16:58 +02:00
bors 82bee96507 Auto merge of #155321 - briansmith:b/bufwriter-conservative, r=Mark-Simulacrum
`BufWriter`: Make the soundness of `BorrowedBuf` usage clearer.

The previous safety comment was outdated as it was written before `BorrowedBuf::set_init` was changed to be a boolean. It also failed to address the possibility that `flush_buf` invalidated the assumption.
2026-05-09 18:40:20 +00:00
Jules Bertholet 40da877450 Add str::word_to_titlecase() to alloc
* Add `str::word_to_titlecase()` to `alloc`
* Address review comment
2026-05-09 17:42:42 +00:00
Oli Scherer 664177fdf1 Remove const closure hacks in libstd 2026-05-05 11:35:29 +02:00
bors 783062d3c6 Auto merge of #154095 - joboet:vec_clear_truncate, r=nnethercote
std: implement `clear` via `truncate`

This gets rid of some `unsafe`. `truncate(0)` is even documented to be equivalent to `clear`, this makes that equivalence even more obvious.
2026-05-04 06:16:32 +00:00
Brian Smith d50c54bd53 BufWriter: Make the soundness of BorrowedBuf usage clearer.
The previous safety comment was outdated as it was written before
`BorrowedBuf::set_init` was changed to be a boolean. It also failed
to address the possibility that `flush_buf` invalidated the
assumption.

Simplify the implementation of `flush_buf` to more obviously preserve
the spare capacity, and document the need to preserve the spare
capacity where necessary.
2026-05-02 11:55:41 -07:00
Ralf Jung e402c1edf0 miri: remove retag statements, make typed copies retag implicitly instead 2026-05-02 17:40:33 +02:00
joboet f8b83b23c3 std: don't implement clear via truncate 2026-05-01 16:22:40 +02:00
Jacob Pratt 06fa54768c Rollup merge of #155858 - ChrisDenton:borrowed-len, r=jhpratt
`slice::join`: borrow only once during length calc

This ensures the length calculation will always be self-consistent even if the real length changes when we actually come to use them.

This is a follow up to rust-lang/rust#155708
2026-04-28 05:37:23 -04:00
Jacob Pratt 8985f1f97b Rollup merge of #155847 - DaniPopes:string-push-len, r=jhpratt
Don't reload length in String::push

Same as in `Vec::push_mut`, we get `.len()` once at the start since it won't change in the `reserve()` call.

Saves reloading the length after the allocation: https://godbolt.org/z/W3G165Gd7
2026-04-28 05:37:22 -04:00
Chris Denton b7424bac39 slice::join: borrow only once during length calc
This ensures the length calculation will always be self-consistent even if the real length changes when we actually come to use them.
2026-04-27 20:32:51 +00:00
Jacob Pratt f4043f8c09 Rollup merge of #155708 - Manishearth:borrow-fix, r=Mark-Simulacrum
Fix heap overflow in slice::join caused by misbehaving Borrow

This code allocates a buffer using lengths calculated by calling `.borrow()` on some slices, and then copies them over after again calling `.borrow()`. There is no safety-reliable guarantee that these will return the same slices.

While this code calls `.borrow()` three times, only one of them is problematic: the others already use checked indexing.

I made the test a normal library test, but let me know if it should go elsewhere.

Bug discovered by Rust Foundation Security using AI. I'm just helping with the patch as a member of wg-security-response. We do not believe this bug needs embargo, it is a soundness fix for hard-to-trigger unsoundness.
2026-04-26 21:56:41 -04:00
Jacob Pratt 72cd5fba78 Rollup merge of #155579 - Gaming32:fix-154998, r=Mark-Simulacrum
Make Rcs and Arcs use pointer comparison for unsized types

`Rc` and `Arc`s have an `Eq` implementation that first attempt to compare the pointers as an optimization. This, however, was not extended to DSTs, which is what this PR fixes.

Fixes rust-lang/rust#154998.
2026-04-26 21:56:40 -04:00
Manish Goregaokar da545d0856 Fix heap overflow in slice::join caused by misbehaving Borrow
* Fix heap overflow in slice join via inconsistent Borrow
* Update library/alloc/src/str.rs

Co-authored-by: Mark Rousskov <mark.simulacrum@gmail.com>
2026-04-26 23:20:32 +00:00
DaniPopes 34e1e172b2 Don't reload length in String::push
Same as in Vec::push_mut, we get `.len()` once at the start since
it won't change in the `reserve()` call.

Saves reloading the length after the allocation: https://godbolt.org/z/W3G165Gd7
2026-04-27 00:32:43 +02:00
Manish Goregaokar b4e013bbec fix cstr clone_into unsoundness 2026-04-24 00:15:42 +00:00
Josiah Glosson 6f28cd5073 Make Rcs and Arcs use pointer comparison for unsized types 2026-04-20 21:48:58 -05:00
Lars Schumann 2ba7b3b537 constify vec comparisons 2026-04-20 16:00:18 +00:00
Jonathan Brouwer ce91732a75 Rollup merge of #155054 - Lars-Schumann:const-vec-ops, r=dtolnay
constify `Index(Mut)`, `Deref(Mut)` for `Vec`

Relevant tracking issues
const_convert: https://github.com/rust-lang/rust/issues/143773
const_index: https://github.com/rust-lang/rust/issues/143775
2026-04-20 08:14:09 +02:00
Jonathan Brouwer 92a2343356 Rollup merge of #146870 - DiuDiu777:box-doc-fix, r=Mark-Simulacrum
fix: add aliasing rules for Box

This is a new revised version for the PR [139857](https://github.com/rust-lang/rust/pull/139857), sorry for the delayed reply. I've rewritten the sentence to closely mirror the wording from `Vec::from_raw_parts`, which clearly states the transfer of ownership and its consequences. This should make the aliasing requirements much clearer.

I opted not to include a note about `mem::forget` by default to keep the documentation focused on the primary contract, similar to `Vec`.
2026-04-18 19:23:13 +02:00
Jonathan Brouwer f67a3759bf Rollup merge of #155049 - quixoticaxis:weak-upgrade-documentation-extension, r=jhpratt
Documenting the case of `Weak::upgrade` returning `None` when the value behind the reference is missing

Adds a clause to the documentation of `Weak` for `Arc` which was discussed in rust-lang/rust#154936.

Adds the same clause to the documentation of `Weak` for `Rc`, because the behavior is the same.
2026-04-17 13:28:59 +02:00
Sergey Ivanov f580872fe2 Extended the documentation for Arc's Weak::upgrade 2026-04-17 07:47:34 +00:00
Stuart Cook 16b22a7e0f Rollup merge of #155305 - Zoxc:ub-issue-2, r=tgross35
Make `convert_while_ascii` unsafe

`convert_while_ascii` assumes `convert` only returns ASCII to ensure the output remains valid UTF-8. This adds that requirement as a safety precondition.
2026-04-17 16:17:55 +10:00
Stuart Cook 3c61fba50b Rollup merge of #154491 - Jules-Bertholet:case-docs, r=Mark-Simulacrum,GuillaumeGomez
Extend `core::char`'s documentation of casing issues (and fix a rustdoc bug)

@rustbot label A-unicode A-docs
2026-04-17 16:17:50 +10:00
John Kåre Alsaker 99ed1b81d7 Make convert_while_ascii unsafe 2026-04-14 20:27:30 +02:00
LemonJ c6befd82ce fix: add aliasing rules for Box 2026-04-12 09:07:07 +08:00
Jonathan Brouwer 9a24dbf885 Rollup merge of #154925 - zachs18:heap-into-array-with-alloc, r=Mark-Simulacrum
Make Box/Rc/Arc::into_array allocator-aware (and add doctest)

Tracking issue for `alloc_slice_into_array`: https://github.com/rust-lang/rust/issues/148082

Tracking issue for `allocator_api`: https://github.com/rust-lang/rust/issues/32838

Make the `into_array` methods on `Box`, `Rc`, and `Arc` allocator-aware.

I think the allocator-aware-ness should not be observable on stable, so these should not be additionally (comment-)gated behind `feature(allocator_api)`, just like e.g. `Box::leak` and `Vec::into_boxed_slice`. The added doctests do not use `feature(allocator_api)`.

@rustbot label T-libs-api
2026-04-11 20:58:37 +02:00
Jules Bertholet cd061c73af Extend core::char's documentation of casing issues
* Extend `core::char`'s documentation of casing issues
* Fix typos
* Fix typo

Co-authored-by: GrigorenkoPV <GrigorenkoPV+github@yandex.ru>
* Document maximum 3x character expansion

This is guaranteed by Unicode.
* Fix error in `str` casing method docs
2026-04-11 15:19:20 +00:00
Lars Schumann 804f4953d2 constify Index(Mut), Deref(Mut) for Vec 2026-04-09 16:31:12 +00:00
bors c753cef0df Auto merge of #154976 - jhpratt:rollup-e8XWRVU, r=jhpratt
Rollup of 4 pull requests

Successful merges:

 - rust-lang/rust#154460 (Deduplication: Pulled common logic out from lower_const_arg_struct)
 - rust-lang/rust#154609 (Enable `#[diagnostic::on_const]` for local impls)
 - rust-lang/rust#154678 (Introduce #[diagnostic::on_move] on `Rc`)
 - rust-lang/rust#154902 (rustdoc: Inherit inline attributes for declarative macros)
2026-04-08 05:22:42 +00:00
bors 30d0309fa8 Auto merge of #148486 - kpreid:vec-iter-drop, r=jhpratt
Explicitly forget the zero remaining elements in `vec::IntoIter::fold()`.



[Original description:] ~~This seems to help LLVM notice that dropping the elements in the destructor of `IntoIter` is not necessary. In cases it doesn’t help, it should be cheap since it is just one assignment.~~

This PR adds a function to `vec::IntoIter()` which is used used by `fold()` and `spec_extend()`, when those operations complete, to forget the zero remaining elements and only deallocate the allocation, ensuring that there will never be a useless loop to drop zero remaining elements when the iterator is dropped.

This is my first ever attempt at this kind of codegen micro-optimization in the standard library, so please let me know what should go into the PR or what sort of additional systematic testing might indicate this is a good or bad idea.
2026-04-08 02:06:51 +00:00
Zachary S 7d35719021 Add doctest for Box/Rc/Arc::into_array 2026-04-06 23:54:50 -05:00
Zachary S 938c5b5df6 Make Box/Rc/Arc::into_array allocator-aware 2026-04-06 23:41:37 -05:00
Romain Perier 92ed4a21ff Introduce #[diagnostic::on_move] on Rc
This annotates the `Rc` type with the diagnostic attribute
`#[diagnostic::on_move]`. Now when a moved `Rc` is borrowed,
a suggestion to clone it is made, with a label explaining why.
2026-04-06 19:05:55 +02:00
Jonathan Brouwer 6bf2ce0f38 Rollup merge of #154849 - Jules-Bertholet:case-ignorable, r=Mark-Simulacrum
Promote `char::is_case_ignorable` from perma-unstable to unstable

(Take two of https://github.com/rust-lang/rust/pull/154658, which was closed when GitHub Codespaces somehow managed to squash the entire commit history of rust-lang/rust into one commit)

This function is currently used in the implementation of `str::to_lowercase()`. There is no reason to restrict it to the stdlib, though. Reimplementations of string casing for types other than `str` -> `String` shouldn't need to waste space with a duplicate copy of this table.

@rustbot label A-unicode T-libs-api

r? @Mark-Simulacrum
2026-04-06 08:27:52 +02:00
Jules Bertholet c88ef81131 Promote char::is_case_ignorable from perma-unstable to unstable 2026-04-05 13:35:09 +00:00
Jonathan Brouwer a660f77505 Rollup merge of #154461 - lms0806:issue_154452, r=Mark-Simulacrum
Edit the docs new_in() and with_capacity_in()

I have updated the documentation for new_in().

While reviewing the code, I noticed that the documentation for with_capacity_in() was also inaccurate, so I have corrected it.

Close rust-lang/rust#154452
2026-04-04 17:19:11 +02:00
Jonathan Brouwer ab3532f487 Rollup merge of #154581 - GrigorenkoPV:extract-if-debug, r=Mark-Simulacrum
More informative `Debug for vec::ExtractIf`

While working on rust-lang/rust#154318, I've realized that `vec::ExtractIf` actually maintains a valid prefix and a valid suffix in the underlying vector at all times with all the temporarily-invalid elements being only in the middle.

So why not make the `Debug` output more informative? I guess we could even expose something like `get_retained_mut(&mut self) -> &mut [T]` and `get_remainder_mut(&mut self) -> &mut [T]`, but that would add new backwards compatibility burden, unlike the `Debug` implementation, which (IIRC) can be changed at any time.
2026-04-04 17:19:11 +02:00
Romain Perier 12f8364d4d Introduce #[diagnostic::on_move] on Arc
This annotates the `Arc` type with the diagnostic attribute
`#[diagnostic::on_move]`. Now when a moved `Arc` is borrowed,
a suggestion to clone it is made, with a label explaining why.
2026-04-01 11:00:54 +02:00
Trevor Gross 59fe28d0ff compiler-builtins: Clean up features
Remove the `compiler-builtins` feature from default because it prevents
testing via the default `cargo test` command. It made more sense as a
default when `compiler-builtins` was a dependency that some crates added
via crates.io, but is no longer needed.

The `rustc-dep-of-std` feature is also removed since it doesn't do
anything beyond what the `compiler-builtins` feature already does.
2026-03-30 18:45:13 -04:00
Pavel Grigorenko 6c46776304 Debug for vec::ExtractIf 2026-03-30 13:01:46 +03:00
lms0806 a374727025 resolve: issue 154452 solve 2026-03-30 16:31:15 +09:00
Jonathan Brouwer b7ea4b70db Rollup merge of #154520 - GrigorenkoPV:doc/extract_if, r=JohnTitor
Add doc links to `ExtractIf` of `BTree{Set,Map}` and `LinkedList`

There were links for `Hash{Set,Map}` and `Vec{,Deque}` versions, but not these three.
2026-03-29 08:59:39 +02:00
Jonathan Brouwer 8287d4deb2 Rollup merge of #153632 - Lars-Schumann:issue-153158, r=fee1-dead
Fix Vec::const_make_global for 0 capacity and ZST's

fixes https://github.com/rust-lang/rust/issues/153158
2026-03-29 08:59:35 +02:00
Pavel Grigorenko 18a3bda091 Add doc links to ExtractIf of BTree{Set,Map} and LinkedList 2026-03-29 01:11:52 +03:00
Stuart Cook 4c86e7c565 Rollup merge of #154221 - DanielEScherzer:isize-lc, r=Mark-Simulacrum
`vec::as_mut_slice()`: use lowercase "isize" in safety comment

To match other references to that type
2026-03-28 15:01:39 +11:00
Stuart Cook 3c6a2bc0af Rollup merge of #154081 - safer-rust:main, r=Mark-Simulacrum
format safety doc of Rc/Arc::from_raw/from_raw_in

The following APIs previously had safety notes, but they were not placed under a dedicated Safety section. This PR adds a Safety section for each API and moves the original safety descriptions there:
- [`Rc::from_raw`](https://doc.rust-lang.org/nightly/alloc/rc/struct.Rc.html#method.from_raw)
- [`Rc::from_raw_in`](https://doc.rust-lang.org/nightly/alloc/rc/struct.Rc.html#method.from_raw_in)
- [`Arc::from_raw`](https://doc.rust-lang.org/nightly/alloc/sync/struct.Arc.html#method.from_raw)
- [`Arc::from_raw_in`](https://doc.rust-lang.org/nightly/alloc/sync/struct.Arc.html#method.from_raw_in)

Additionally, we updated the parameter requirements to clarify that the raw pointer may be returned not only from `into_raw`, but also from `into_raw_with_allocator`.
2026-03-28 15:01:37 +11:00
bors ac40f5e105 Auto merge of #154004 - GrigorenkoPV:alignment/as_nonzero_usize, r=scottmcm
`Alignment`: move from `ptr` to `mem` and rename `as_nonzero` to `as_nonzero_usize`



- tracking issue: rust-lang/rust#102070
- split off from rust-lang/rust#153261
2026-03-27 01:25:29 +00:00
Pavel Grigorenko ba1e06a722 core::mem::Alignemnt: rename as_nonzero to as_nonzero_usize 2026-03-25 16:18:33 +03:00
Pavel Grigorenko f8d658ab81 core: move Alignment from ptr to mem 2026-03-25 16:18:33 +03:00