Commit Graph

3696 Commits

Author SHA1 Message Date
Jacob Pratt 9c63e94ef7 Rollup merge of #156810 - Teufelchen1:fix_doc_typo, r=SimonSapin
Fix doc typo in Vec::into_array and convert Arc/Box/Rc::into_arry to -> Result

Hello 🪼,

the first commit fixes a documentation mistake added in the recent PR rust-lang/rust#156234

The second commit addresses three function signature changes as defined by the tracking issue rust-lang/rust#148082
It converts all `.into_array() -> Option<>` into `.into_array() -> Result<>`

The third commit is a fixup for the second. The change is needed as calling `unwrap()` on `Err(E)` requires `E` to implement `Debug`. I thought `Vec<T, A> where T: Debug` is not an acceptable solution, so I tried to come up with my own. I am *NOT* confident in my `unsafe {}`  code due to lack of expierence, please check extra carefully.

Appreciating feedback & greetings from the RustWeek,
Thanks!
2026-05-24 16:39:41 +02:00
Bennet Blischke 8b382d62df Return result instead of option by Arc/Rc/Box::into_array 2026-05-24 11:39:35 +02:00
Jonathan Brouwer eb68b36521 Rollup merge of #156828 - P8L1:share-trait-core-bootstrap, r=SimonSapin
Add unstable Share trait

Tracking issue: rust-lang/rust#156756

This adds an initial unstable `Share` trait for clone-as-alias types, as part of the 2026 ergonomic ref-counting project goal.

```rust
pub trait Share: Clone {
    fn share(&self) -> Self {
        Clone::clone(self)
    }
}
```

This PR adds a separate unstable feature gate:

```rust
#![feature(share_trait)]
```

and places the trait next to `Clone` in `core::clone`.

Implemented initial impls:

- `impl<T: ?Sized> Share for &T`
- `impl<T: ?Sized, A: Allocator + Clone> Share for Rc<T, A>`
- `impl<T: ?Sized, A: Allocator + Clone> Share for Arc<T, A>`
- `impl<T> Share for std::sync::mpsc::Sender<T>`
- `impl<T> Share for std::sync::mpsc::SyncSender<T>`

The PR deliberately does not add `Share` to the prelude.

r? @nikomatsakis
@rustbot label F-ergonomic_clones
2026-05-24 08:27:21 +02:00
Pieter-Louis Schoeman 9b3cd578ab Remove provisional Share trait FIXME notes 2026-05-22 07:13:06 +02:00
bors 3bf5c6d99b Auto merge of #152112 - Kobzol:vec-deque-strongly-typed, r=joboet
Use strongly typed wrapped indices in `VecDeque`



This is far from perfect, but it would have prevented https://github.com/rust-lang/rust/pull/151769.

r? @joboet
2026-05-22 02:21:11 +00:00
Pieter-Louis Schoeman 78b0f9db85 Add Share impl for Arc 2026-05-22 00:11:38 +02:00
Pieter-Louis Schoeman fc33b6d4f4 Add Share impl for Rc 2026-05-22 00:09:24 +02:00
Bennet Blischke d9ab6d6e2d Correct doc of Vec::into_array: Returns Err(Self) instead of None 2026-05-21 18:07:22 +02:00
Jonathan Brouwer 27d3139405 Rollup merge of #155840 - Lars-Schumann:prefer-is-zst, r=clarfonthey
prefer `T::IS_ZST` over manual check

makes the intent clearer and possible small perf improvement
2026-05-18 23:17:17 +02:00
bors 5ea817c65e Auto merge of #149696 - jnodorp:clarify-utf16-errors, r=SimonSapin
Clarify UTF-16 decoding errors

Fix UTF-16 error messages as suggested in rust-lang/rust#116258.
2026-05-18 04:49:52 +00:00
Jonathan Brouwer acd0707333 Rollup merge of #156234 - bend-n:into_array_for_vec_t_via_boxed_array, r=SimonSapin
implement `into_array` for `Vec<T>`

for more into_array coverage and to avoid harmful obtuse opaque try_into calls
2026-05-18 03:19:46 +02:00
Lars Schumann 6eefc1b28d prefer T::IS_ZST over manual check 2026-05-17 22:52:25 +00:00
Jonathan Brouwer 845f3d30bf Rollup merge of #156556 - qaijuang:issue-156491-str-replace-utf8-pattern, r=ChrisDenton
Require UTF-8 in `Utf8Pattern::StringPattern`

Store `&str` instead, so the UTF-8 invariant is enforced at the API boundary.

Fixes rust-lang/rust#156491
2026-05-15 20:11:46 +02:00
bors 88ba7fbe0a Auto merge of #155360 - malezjaa:try_insert_changes, r=cuviper
map_try_insert changes





Made changes according to https://github.com/rust-lang/rust/issues/82766#issuecomment-4253028464.

r? @tgross35
2026-05-15 08:12:52 +00:00
Qai Juang 8909e794e7 Require UTF-8 in Utf8Pattern::StringPattern 2026-05-14 21:26:00 -04:00
malezjaa ca70543ca4 map_try_insert changes 2026-05-14 22:36:03 +02:00
ast-ral ed2f960d5b fix missing space in Rc::decrement_strong_count 2026-05-11 17:09:34 -07:00
bendn d8502aa007 implement into_array for Vec<T> 2026-05-11 16:38:54 +07:00
Jakub Beránek aa9f27e865 Rename WrappedIndex::new to from_arbitrary_number and resolve review remarks 2026-05-10 10:11:50 +02:00
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
Jakub Beránek 207d3bd5f0 Change abs_diff return type to usize 2026-05-09 11:55:38 +02:00
Jakub Beránek e36f74d3b8 Use strongly typed wrapped indices in VecDeque 2026-05-09 11:55:37 +02: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