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
`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.
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.
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.
`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
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
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.
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.
Fixesrust-lang/rust#154998.
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
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`.
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.
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.
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
* 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
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)
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.
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.
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
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.
Closerust-lang/rust#154452
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.
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.
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.
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.