Commit graph

107 commits

Author SHA1 Message Date
BD103
e027ecdbb5 feat: support arrays in type reflection 2026-01-13 12:18:57 -05:00
Matthias Krüger
807a5cefd2
Rollup merge of #147938 - const-clone-slice, r=tgross35
Add const cloning of slices and tests

As discussed in https://github.com/rust-lang/rust/pull/143628#discussion_r2390170336, splitting off slice cloning as a separate PR.
r? @tgross35
2026-01-12 00:02:52 +01:00
Matthias Krüger
30f9939a0c
Rollup merge of #148941 - stabilize-map-if, r=jhpratt
stabilize `Peekable::next_if_map` (`#![feature(peekable_next_if_map)]`)

# Stabilization report

## Summary

`#![feature(peekable_next_if_map)]` is a variation  of `next_if` on peekable iterators that can transform the peeked item. This creates a way to take ownership of the next item in an iterator when some condition holds, but put the item back when the condition doesn't hold. This pattern would otherwise have needed unwraps in many cases.

[Tracking issue](https://github.com/rust-lang/rust/issues/143702)

### What is stabilized

```rust
impl<I: Iterator> Peekable<I> {
    pub fn next_if_map<R>(
        &mut self,
        f: impl FnOnce(I::Item) -> Result<R, I::Item>,
    ) -> Option<R> {
        ..
    }
    pub fn next_if_map_mut<R>(
        &mut self,
        f: impl FnOnce(&mut I::Item) -> Option<R>,
    ) -> Option<R> {
        ..
    }
}
```

Example usage adapted from the ACP:

```rust
let mut it = Peekable::new("123".chars());

while let Some(digit) = it.next_if_map(|c| c.to_digit(10).ok_or(c)) {
    codepoint = codepoint * 10 + digit;
}
```

or with `next_if_map_mut`:

```rust
let mut it = Peekable::new("123".chars());

while let Some(digit) = iter.next_if_map_mut(|c| c.to_digit(10)) {
    line_num = line_num * 10 + digit;
}
```

Note that the major difference here is that `next_if_map_mut` does not get owned items from the iterator, but mutable references. With that api, the closure can return an `Option` which avoids an `ok_or`. This may require cloning or copying the iterator elements, so if that is expensive, the owned version, `next_if_map`, may be preferable.

### Nightly use

At the moment, this feature is barely used in nightly, though I've found multiple good uses for it in my own projects, hence my pushing for stabilization. It makes the kind of patterns used in recursive descent parsing super concise and maybe with its stabilization it will find more use.

### Test coverage

Besides a quite comprehensive doctest, this feature is tested (including panicking in the closure) here:

c880acdd31/library/coretests/tests/iter/adapters/peekable.rs (L275-L359)

## History

- ACP: https://github.com/rust-lang/libs-team/issues/613 accepted with https://github.com/rust-lang/libs-team/issues/613#issuecomment-3049844223
- implementation: https://github.com/rust-lang/rust/pull/143725 with tests, and no issues reported since july.

## Acknowledgments

ACP, implementation and tracking issue for this feature all by @kennytm <3
2026-01-11 09:56:37 +01:00
Jana Dönszelmann
dc3786eb3c
stabilize map_next_if 2025-12-17 14:14:17 +01:00
usamoi
141342c34f stabilize lazy_get 2025-12-15 18:57:33 +08:00
Evgenii Zheltonozhskii
c1472c573a Add const cloning of slices and tests 2025-12-12 06:31:00 +02:00
Matthias Krüger
26ae47502a
Rollup merge of #148052 - tgross35:stabilize-const_mul_add, r=RalfJung
Stabilize `const_mul_add`

Newly stable API:

```rust
impl {f32, f64} {
    pub const fn mul_add(self, a: Self, b: Self) -> Self;
}
```

This includes making the intrinsics `fmaf{16,32,64,128}` const stable for indirect use, matching similar intrinsics.

Closes: https://github.com/rust-lang/rust/issues/146724
2025-12-10 17:16:46 +01:00
Matthias Krüger
8a6f82efac
Rollup merge of #148814 - bend-n:stabilize_array_windows, r=scottmcm
stabilize `array_windows`

Tracking issue: rust-lang/rust#75027
Closes: rust-lang/rust#75027
FCP completed: https://github.com/rust-lang/rust/issues/75027#issuecomment-3477510526
2025-12-06 09:57:59 +01:00
bendn
919e46f4d4
stabilize [T]::array_windows 2025-12-02 00:37:17 +07:00
Matthias Krüger
9a967de929
Rollup merge of #148690 - IntegralPilot:clamp-mag, r=joboet
Implement `clamp_magnitude` method for primitive floats & signed integers

Tracking issue rust-lang/rust#148519
ACP https://github.com/rust-lang/libs-team/issues/686
2025-12-01 17:55:05 +01:00
MolecularPilot
ae7fa32e5b Implement clamp_magnitude for floats & signed integers
Added feature gate, documentation and tests also.
2025-12-01 17:04:25 +11:00
bendn
1d718e20ac
constify from_fn, try_from_fn, try_map, map 2025-11-27 20:16:46 +07:00
bendn
eddf2f8c68
tests 2025-11-27 20:16:43 +07:00
Stuart Cook
e3ecd4530b
Rollup merge of #149097 - okaneco:gather_scatter_bits, r=Mark-Simulacrum
num: Implement `uint_gather_scatter_bits` feature for unsigned integers

Feature gate: `#![feature(uint_gather_scatter_bits)]`
Tracking issue: https://github.com/rust-lang/rust/issues/149069
Accepted ACP: https://github.com/rust-lang/libs-team/issues/695#issuecomment-3549284861

Implement `gather_bits`, `scatter_bits` functions on unsigned integers
Add tests to coretests

This implementation is a small improvement over the plain naive form (see the [solution sketch](https://github.com/rust-lang/libs-team/issues/695)).
We only check the set bits in the mask instead of iterating over every bit.
2025-11-27 12:36:50 +11:00
Stuart Cook
a32d3103d5
Rollup merge of #148048 - thaliaarchi:stabilize-maybeuninit-write-slice, r=Mark-Simulacrum
Stabilize `maybe_uninit_write_slice`

Stabilize feature `maybe_uninit_write_slice` (closes https://github.com/rust-lang/rust/issues/79995).

Note that this also const-stabilizes `<[MaybeUninit<_>]>::write_copy_of_slice`. That method depends on `<[_]>::copy_from_slice`, which is already const-stable, and `<[MaybeUninit<_>]>::assume_init_mut` which is now also stable.
2025-11-27 12:36:48 +11:00
okaneco
7f89192f36 num: Implement uint_gather_scatter_bits feature for unsigned integers
Implement `gather_bits`, `scatter_bits` functions on unsigned integers
Add tests to coretests
2025-11-24 10:03:44 -05:00
Ralf Jung
b032fac34e stabilize duration_from_nanos_u128 2025-11-06 18:08:29 +01:00
Jieyou Xu
4aeb297064
Revert "unicode_data refactors RUST-147622"
This PR reverts RUST-147622 for several reasons:

1. The RUST-147622 PR would format the generated core library code using
   an arbitrary `rustfmt` picked up from `PATH`, which will cause
   hard-to-debug failures when the `rustfmt` used to format the
   generated unicode data code versus the `rustfmt` used to format the
   in-tree library code.
2. Previously, the `unicode-table-generator` tests were not run under CI
   as part of `coretests`, and since for `x86_64-gnu-aux` job we run
   library `coretests` with `miri`, the generated tests unfortunately
   caused an unacceptably large Merge CI time regression from ~2 hours
   to ~3.5 hours, making it the slowest Merge CI job (and thus the new
   bottleneck).
3. This PR also has an unintended effect of causing a diagnostic
   regression (RUST-148387), though that's mostly an edge case not
   properly handled by `rustc` diagnostics.

Given that these are three distinct causes with non-trivial fixes, I'm
proposing to revert this PR to return us to baseline. This is not
prejudice against relanding the changes with these issues addressed, but
to alleviate time pressure to address these non-trivial issues.
2025-11-03 19:53:11 +08:00
Matthias Krüger
01ab3e369b
Rollup merge of #146260 - Qelxiros:146179-sliceindex-wrappers, r=jhpratt
add SliceIndex wrapper types Last and Clamp<Idx>

Tracking issue: rust-lang/rust#146179
2025-11-03 06:54:35 +01:00
Matthias Krüger
75fbbd32f0
Rollup merge of #147622 - Kmeakin:km/unicode-data/refactors, r=joboet
`unicode_data` refactors

Minor refactors to `unicode_data` that occured to me while trying to reduce the size of the tables. Splitting into a separate PR. NFC
2025-10-31 18:41:48 +01:00
Karl Meakin
0e6131c9aa refactor: make unicode_data tests normal tests
Instead of generating a standalone executable to test `unicode_data`,
generate normal tests in `coretests`. This ensures tests are always
generated, and will be run as part of the normal testsuite.

Also change the generated tests to loop over lookup tables, rather than
generating a separate `assert_eq!()` statement for every codepoint. The
old approach produced a massive (20,000 lines plus) file which took
minutes to compile!
2025-10-31 14:12:17 +00:00
ltdk
6f649e4e1a const select_unpredictable 2025-10-26 21:33:00 -04:00
Trevor Gross
033711ce8d Stabilize const_mul_add
Newly stable API:

    impl {f32, f64} {
        pub const fn mul_add(self, a: Self, b: Self) -> Self;
    }

This includes making the intrinsics `fmaf{16,32,64,128}` const stable
for indirect use, matching similar intrinsics.

Closes: https://github.com/rust-lang/rust/issues/146724
2025-10-23 17:10:59 -04:00
Thalia Archibald
5088b3816b Stabilize maybe_uninit_write_slice 2025-10-23 14:02:41 -06:00
ltdk
97b7170eef const Cell methods 2025-10-16 16:09:31 -04:00
Matthias Krüger
252974a717
Rollup merge of #146187 - clarfonthey:const-drop-in-place, r=oli-obk
Unstably constify `ptr::drop_in_place` and related methods

Tracking: rust-lang/rust#109342
Supercedes: rust-lang/rust#145725

Makes methods const:

* `core::ptr::drop_in_place`
* `core::mem::ManuallyDrop::drop`
* `core::mem::MaybeUninit::assume_init_drop`
* `<[core::mem::MaybeUninit<_>]>::assume_init_drop`
* `<*mut _>::drop_in_place`
* `core::ptr::NonNull::drop_in_place`
2025-10-14 19:47:28 +02:00
Jeremy Smart
a00f24116e
unstably constify float mul_add methods
Co-authored-by: Ralf Jung <post@ralfj.de>
2025-09-24 15:21:31 -04:00
Jeremy Smart
78d8ce7301
add SliceIndex wrapper types Last and Clamp<Idx> 2025-09-15 15:25:12 -04:00
Matthias Krüger
9070e95dda
Rollup merge of #146478 - ferrocene:pvdrz/improve-fmt-coverage, r=Mark-Simulacrum
Improve `core::fmt` coverage

This PR improves the `core::fmt` coverage by adding new tests to `coretests`
2025-09-15 06:03:46 +02:00
Jana Dönszelmann
7928be014c
Rollup merge of #146477 - ferrocene:pvdrz/improve-char-coverage, r=Noratrieb
Improve `core::char` coverage

This PR improves the `core::char` coverage by adding new tests to `coretests`

r? ``@workingjubilee``
2025-09-13 02:40:45 +02:00
Christian Poveda
2e652d7d13
Improve core::fmt coverage 2025-09-12 11:34:54 -05:00
Christian Poveda
51e3b6238d
Improve core::char coverage 2025-09-12 11:22:07 -05:00
Evgenii Zheltonozhskii
ff9b1c1d28 Constify Eq, Ord, PartialOrd 2025-09-12 12:39:31 +03:00
Christian Poveda
5f2b04652f
Improve core::ops coverage 2025-09-10 16:32:04 -05:00
ltdk
07d3e923ac Unstably constify ptr::drop_in_place and related methods 2025-09-05 17:28:22 -04:00
Jacob Pratt
00d5dc5c9d
Rollup merge of #145690 - sayantn:integer-funnel-shift, r=tgross35
Implement Integer funnel shifts

Tracking issue: rust-lang/rust#145686
ACP: https://github.com/rust-lang/libs-team/issues/642

This implements funnel shifts on primitive integer types. Implements this for cg_llvm, with a fallback impl for everything else

Thanks `@folkertdev` for the fixes and tests

cc `@rust-lang/libs-api`
2025-09-04 01:43:21 -04:00
Stuart Cook
732802c207
Rollup merge of #143725 - kennytm:peekable_next_if_map, r=jhpratt
core: add Peekable::next_if_map

Implementation for rust-lang/rust#143702
2025-09-04 10:01:51 +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
sayantn
62b4347e80
Add funnel_sh{l,r} functions and intrinsics
- Add a fallback implementation for the intrinsics
 - Add LLVM backend support for funnel shifts

Co-Authored-By: folkertdev <folkert@folkertdev.nl>
2025-09-03 14:13:24 +05:30
ltdk
1c64d3e6d1 Constify conversion traits 2025-09-01 21:38:26 -04:00
Stuart Cook
f655e6a863
Rollup merge of #145969 - actuallylost:duration-from-nanos-128, r=tgross35
Add Duration::from_nanos_u128

Feature Gate: `#![feature(duration_from_nanos_u128)]`
ACP: https://github.com/rust-lang/libs-team/issues/567
Tracking issue: https://github.com/rust-lang/rust/issues/139201
Recreated from https://github.com/rust-lang/rust/pull/139243
2025-08-30 20:29:08 +10:00
Trevor Gross
ed9e767c01
Rollup merge of #145467 - Kivooeo:stabilize-strict_provenance_atomic_ptr, r=scottmcm
Stabilize `strict_provenance_atomic_ptr` feature

This closes [tracking issue](https://github.com/rust-lang/rust/issues/99108) and stabilises `AtomicPtr::{fetch_ptr_add, fetch_ptr_sub, fetch_byte_add, fetch_byte_sub, fetch_or, fetch_and, fetch_xor}`

---

EDIT: FCP completed at https://github.com/rust-lang/rust/issues/99108#issuecomment-3168260347
2025-08-29 19:33:02 -05:00
actuallylost
8134a10ec7 Add Duration::from_nanos_u128
Tracking issue: RUST-139201

Co-authored-by: omanirudh <omanirudh2014@gmail.com>
2025-08-30 01:38:14 +03:00
Matthias Krüger
1e90922864
Rollup merge of #144274 - Qelxiros:option-reduce, r=tgross35
add Option::reduce

Tracking issue: rust-lang/rust#144273
2025-08-27 11:26:48 +02:00
ltdk
2914291e09 Move WTF-8 code from std to core/alloc 2025-08-20 20:31:33 -04:00
Jacob Pratt
5a0c9386a2
Rollup merge of #145381 - Gnurou:int_lowest_highest_one, r=jhpratt
Implement feature `int_lowest_highest_one` for integer and NonZero types

Tracking issue: rust-lang/rust#145203

Implement the accepted ACP rust-lang/rust#145203 for methods that find the index of the least significant (lowest) and most significant (highest) set bit in an integer for signed, unsigned, and NonZero types.

Also add unit tests for all these types.
2025-08-20 00:45:56 -04:00
Stuart Cook
027c7a5d85
Rollup merge of #141744 - GrigorenkoPV:ip_from, r=Amanieu
Stabilize `ip_from`

Tracking issue: rust-lang/rust#131360

Stabilizes and const-stabilizes the following APIs:
```rust
// core::net
impl Ipv4Addr {
    pub const fn from_octets(octets: [u8; 4]) -> Ipv4Addr;
}
impl Ipv6Addr {
    pub const fn from_octets(octets: [u8; 16]) -> Ipv6Addr;
    pub const fn from_segments(segments: [u16; 8]) -> Ipv6Addr;
}
```

Closes rust-lang/rust#131360

```@rustbot``` label +needs-fcp
2025-08-19 14:18:15 +10:00
Alexandre Courbot
73d3d28bed Implement feature int_lowest_highest_one for integer and NonZero types
Implement the accepted ACP for methods that find the index of the least
significant (lowest) and most significant (highest) set bit in an
integer for signed, unsigned, and NonZero types.

Also add unit tests for all these types.
2025-08-18 18:59:44 +09:00
Jacob Pratt
2776a21a4f
Rollup merge of #144963 - rossmacarthur-forks:stabilize-core-iter-chain, r=jhpratt
Stabilize `core::iter::chain`

Closes rust-lang/rust#125964
2025-08-15 18:13:29 -04:00
Kivooeo
b951b5dca1 stabilize strict provenance atomic ptr 2025-08-15 16:56:11 +00:00