Commit Graph

3642 Commits

Author SHA1 Message Date
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
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
Theemathas Chirananthavat 1e4c1d6f75 Make PinCoerceUnsized require Deref
Also, delete impls on non-Deref types.

Pin doesn't do anything useful for non-Deref types, so PinCoerceUnsized
on such types makes no sense.

This is a breaking change, since stable code can observe the deleted
`PinCoerceUnsized` impls by uselessly coercing between such types
inside a `Pin`.

There is still some strange behavior, such as `Pin<&mut i32>` being
able to coerce to `Pin<&dyn Send>`, but not being able to coerce to
`Pin<&i32>`. However, I don't think it's possible to fix this.

Fixes https://github.com/rust-lang/rust/issues/145081
2026-03-25 11:40:27 +07:00
Jonathan Brouwer 3cad6d130a Rollup merge of #122668 - Jules-Bertholet:titlecase, r=Mark-Simulacrum
Add APIs for dealing with titlecase

ACP: https://github.com/rust-lang/libs-team/issues/354
Tracking issue: https://github.com/rust-lang/rust/issues/153892

r? libs-api

@rustbot label T-libs -T-libs-api A-unicode

~~The last commit has some insta-stable `PartialEq` impls, therefore: @rustbot label -needs-fcp
Alternatively, I could split those out into a follow-up PR.~~ (Edit: will do in follow-up)
2026-03-23 20:18:32 +01:00
Jonathan Brouwer adb4d2ed27 Rollup merge of #154011 - usamoi:binary_heap_as_mut_slice, r=Mark-Simulacrum
implement `BinaryHeap::as_mut_slice`

Tracking issue: https://github.com/rust-lang/rust/issues/154009
2026-03-23 12:14:58 +01:00
Jonathan Brouwer 102a701020 Rollup merge of #153107 - asder8215:btreemap_append_optimized, r=Mark-Simulacrum
Optimize BTreeMap::append() using CursorMut

Since [`BTreeMap::merge`](https://github.com/rust-lang/rust/pull/152418#issuecomment-3959764862) uses `CursorMut` to avoid reconstructing the map from scratch and instead inserting other `BTreeMap` at the right places or overwriting the value in self `BTreeMap` on conflict, we might as well do the same for `BTreeMap::append`. This also means that some of the code in `append.rs` can be removed; `bulk_push()` however is used by `bulk_build_from_sorted_iterator()`, which is used by the `From`/`FromIterator` trait impl on `BTreeMap`. Feels like we should rename the file or place the `bulk_push()` in an existing file.

The same additional optimization consideration that `BTreeMap::merge` has is also applied to `BTreeMap::append`.

r? @Mark-Simulacrum  since Mark has seen the `BTreeMap::merge` code already (only diff is the `Ordering::Equal` case and now one of the test assertions on a panic case has the correct value now).
2026-03-23 12:14:52 +01:00
Daniel Scherzer a677f461cb vec::as_mut_slice(): use lowercase "isize" in safety comment
To match other references to that type
2026-03-22 12:11:35 -07:00
Mahdi Ali-Raihan e2a870fd9e Use BTreeMap::merge underneath the hood to deduplicate code 2026-03-21 21:49:37 -04:00
Jules Bertholet 8d072616a5 Add APIs for dealing with titlecase
- `char::is_cased`
- `char::is_titlecase`
- `char::case`
- `char::to_titlecase`
2026-03-21 14:30:38 -04:00
Ralf Jung 43eb70ac97 vec::Drain::fill: avoid reference to uninitialized memory 2026-03-20 13:24:11 +01:00
Jonathan Brouwer ea542a0ea8 Rollup merge of #153824 - samueltardieu:wake-diagnostic-item, r=Mark-Simulacrum
Add `Wake` diagnostic item for `alloc::task::Wake`

The symbol will be defined in Clippy, as Clippy will be the sole user of the diagnostic item so far.
2026-03-19 13:42:29 +01:00
aisr 2c52bc599e format safety doc of Rc/Arc::from_raw/from_raw_in 2026-03-19 17:22:34 +08:00
usamoi cab72ae278 implement BinaryHeap::as_mut_slice 2026-03-18 14:05:08 +08:00
Jonathan Brouwer b1050a74cc Rollup merge of #152998 - xtqqczze:panic-truncate, r=jhpratt
std: make `OsString::truncate` a no-op when `len > current_len`

Align `OsString::truncate` (and the underlying WTF-8 implementation) with `String::truncate` by making it a no-op when `len > self.len()`.

Previously, `OsString::truncate` would panic if `len > self.len()`, while `String::truncate` treats such cases as a no-op.

Tracking (`os_string_truncate`): https://github.com/rust-lang/rust/issues/133262
See also: https://github.com/rust-lang/rust/pull/32977

cc: @alexcrichton, @lolbinarycat
2026-03-17 21:20:01 +01:00
Jules Bertholet c5c1d94e6c Add From impls for wrapper types
- `From<T> for ThinBox<T>`
- `From<T> for UniqueRc<T>`
- `From<T> for UniqueArc<T>`
- `From<T: UnwindSafe> for AssertUnwindSafe<T>`
- `From<T> for LazyCell<T, F>`
- `From<T> for LazyLock<T, F>`
2026-03-14 22:09:35 -04:00
Samuel Tardieu 6e7d6d7821 Add Wake diagnostic item for alloc::task::Wake 2026-03-13 14:57:07 +01:00
Jonathan Brouwer 935805e80a Rollup merge of #153384 - safer-rust:main, r=oli-obk
Add missing safety doc for CString::from_vec_unchecked and async_drop_in_place

Add missing safety documentation for two unsafe APIs:

* `CString::from_vec_unchecked` – # Safety: the caller must ensure `v` contains no NUL bytes in its contents.
* `async_drop_in_place` – # Safety: see [`ptr::drop_in_place`] for safety requirements.
2026-03-13 13:27:49 +01:00
aisr 3771c65b53 add safety doc for CString::from_vec_unchecked and async_drop_in_place 2026-03-13 20:08:37 +08:00
Stuart Cook c5faf3a23a Rollup merge of #152258 - asder8215:vecdeque_splice_151758, r=joboet
fixed VecDeque::splice() not filling the buffer correctly when resizing the buffer on start = end range

This PR fixes rust-lang/rust#151758. The issue came from `Splice::move_tail`, which as joboet pointed out:
> The issue is in move_tail, which resizes the buffer, but fails to account for the resulting hole.

The problem with reserving more space through `VecDeque`'s `buf.reserve()` is that it doesn't update `VecDeque`'s `head`, which means that this code in `move_tail`:
```rust
deque.wrap_copy(
    deque.to_physical_idx(tail_start),
    deque.to_physical_idx(new_tail_start),
    self.tail_len,
);
```
could move over the section of data that `tail_start..tail_start + self.tail_len` of the buffer is supposed to be held at to the incorrect destination since all `.to_physical_idx()` is doing is a wrapping add on the `VecDeque`'s head with the passed in `idx` value.

To avoid this I decided to use `VecDeque::reserve` to both allocate more space into the `VecDeque` if necessary and update head appropriately. However, `VecDeque::reserve` internally relies on the `VecDeque`'s `len` field. Earlier in `VecDeque::splice`, it modifies the `VecDeque`'s `len` constructing the drain via `Drain::new` (as it does a `mem::replace` on `deque.len` with the start bound of the passed in `range`). The `VecDeque`'s `len` can also be potentially modified in the earlier `Splice::fill()` call if it does any replacement towards elements within the passed in `range` value for `VecDeque::splice()`. I needed to temporarily restore the `VecDeque`'s `len` to its actual len, so that `VecDeque::reserve` can work properly. Afterward, you can bring back the `VecDeque`'s `len` to what its value was before and fill the gap appropriately with the rest of the `replace_with` content.

r? @joboet
2026-03-13 14:14:11 +11:00
Jynn Nelson 505d07da28 core and alloc doctests support doctest merging 2026-03-10 11:56:29 +01:00
Lars Schumann 50ee6f9de6 combine 0 capacity and ZST cases 2026-03-10 00:39:33 +00:00
Lars Schumann 98be8f7659 Fix Vec::const_make_global for 0 capacity and ZST's 2026-03-09 23:26:14 +00:00
Josh Stone 78157ddde9 Replace version placeholders with 1.95.0
(cherry picked from commit bad24ccbec)
2026-03-07 10:42:01 -08:00
Jonathan Brouwer 082d0cacd7 Rollup merge of #153399 - bend-n:constify-into-raw-parts, r=Amanieu
constify `Vec::{into, from}_raw_parts{_in|_alloc}`

due to Vec::drop not being const this is kinda necessary to make use of `const_heap`.
2026-03-05 19:41:57 +01:00
bendn 1f1a0bcbb0 constify Vec::{into, from}_raw_parts{_in|_alloc} 2026-03-05 16:01:40 +07:00
Jonathan Brouwer ed9d77216f Rollup merge of #153204 - xtqqczze:must-use-map, r=Amanieu,joboet
Add `#[must_use]` attribute to `HashMap` and `HashSet` constructors

- `new_in`
- `with_capacity_and_hasher`
- `with_capacity_and_hasher_in`
- `with_hasher`
- `with_hasher_in`

See also: https://github.com/rust-lang/rust/issues/89692
2026-03-04 19:30:37 +01:00
Kevin Reid f700fdc001 Explicitly forget the zero remaining elements in vec::IntoIter::fold() and spec_extend().
Adds internal `vec::IntoIter::forget_remaining_elements_and_dealloc()`,
which is 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.
2026-03-03 19:46:06 -08:00
Jonathan Brouwer 671dc27f69 Rollup merge of #153273 - DanielEScherzer:patch-2, r=joboet
vec/mod.rs: add missing period in "ie." in docs

"i.e." is short for the Latin "id est" and thus both letters should be followed by periods.
2026-03-02 20:10:36 +01:00
Daniel Scherzer f538526724 vec/mod.rs: add missing period in "ie." in docs
"i.e." is short for the Latin "id est" and thus both letters should be followed
by periods.
2026-03-01 21:47:52 -08:00
Scott McMurray 2c6ec51564 Update __rust_[rd]ealloc to take NonNull<u8> instead of *mut u8
Passing null to it is [already UB](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2024&gist=8dcd25a549c11de72adc94a668277779) anyway.
2026-02-28 23:49:31 -08:00
Mahdi Ali-Raihan d0a33abd4d fixed VecDeque::splice() not filling the buffer correctly when resizing the buffer on start = end range 2026-02-28 22:28:35 -05:00
xtqqczze dda4f84c56 Add #[must_use] attribute to HashMap and HashSet constructors 2026-02-28 01:22:45 +00:00
xtqqczze 3ecd18ca37 std: make OsString::truncate a no-op when len > current_len
Align `OsString::truncate` (and the underlying WTF-8 implementation) with `String::truncate` by making it a no-op when `len > self.len()`.

Previously, `OsString::truncate` would panic if `len > self.len()`, while `String::truncate` treats such cases as a no-op.
2026-02-27 18:49:45 +00:00