Commit Graph

342 Commits

Author SHA1 Message Date
Amanieu d'Antras 4b07875505 Revert #148937 (Remove initialized-bytes tracking from BorrowedBuf and BorrowedCursor)
This caused several performance regressions because of existing code
which uses `Read::read` and therefore requires full buffer
initialization. This is particularly a problem when the same buffer is
re-used for multiple read calls since this means it needs to be fully
re-initialized each time.

There is still some benefit to landing the API changes, but we will have
to add private APIs so that the existing infrastructure can
track and avoid redundant initialization.
2025-12-17 14:34:56 +00:00
Ivar Flakstad d5bf1a4c9a Introduce vtable_for intrinsic and use it to implement try_as_dyn and try_as_dyn_mut for fallible coercion from &T / &mut T to &dyn Trait. 2025-12-16 06:39:58 -04:00
Matthias Krüger 18fa9ddd77 Rollup merge of #149744 - lemire:main, r=Mark-Simulacrum
test: update duplicate many_digits test to use f64 instead of f32

Replace the f32 test case with an f64 equivalent to improve coverage for parsing large digit counts in double-precision floating-point conversion. Specifically, this PR updates the `many_digits` test in `library/coretests/tests/num/dec2flt/parse.rs` to test f64 (double-precision) parsing instead of f32 (single-precision).

The test verifies that decimal strings with an excessive number of digits (beyond `Decimal::MAX_DIGITS`) are parsed correctly, ensuring proper truncation of insignificant digits. Previously, the same test was repeated twice (see comment https://github.com/rust-lang/rust/pull/86761#issuecomment-3623334228 by `@Viatorus).`

## Changes

- Replaced the duplicated f32 test case with an equivalent f64 test case.
- Updated the expected bit pattern and input string to a very long decimal with many trailing zeros, testing the limits of f64 precision.
2025-12-15 08:08:01 +01:00
Chris Denton 01e40d6755 Rollup merge of #148755 - nxsaken:const_drop_guard, r=dtolnay
Constify `DropGuard::dismiss` and trait impls

Feature: `drop_guard` (rust-lang/rust#144426), `const_convert` (rust-lang/rust#143773), `const_drop_guard` (no tracking issue yet)

Constifies `DropGuard::dismiss` and trait impls.
I reused `const_convert` (rust-lang/rust#143773) for the `Deref*` impls.
2025-12-14 09:18:26 +00:00
nxsaken 0ecf91a701 Use an explicit receiver in DropGuard::dismiss 2025-12-13 14:00:44 +04: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
Daniel Lemire bb549da8f6 test: update duplicate many_digits test to use f64 instead of f32
Replace the f32 test case with an f64 equivalent to improve coverage
for parsing large digit counts in double-precision floating-point
conversion.
2025-12-07 16:51:27 -05: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
Matthias Krüger 8fe12253f7 Rollup merge of #149539 - quaternic:gather-scatter-bits, r=Mark-Simulacrum
Additional test for uN::{gather,scatter}_bits

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

Adds an additional runtime test for `uN::gather_bits` and `uN::scatter_bits` in coretests. They are each other's inverses in a sense, so a shared test can test both with relative ease.

I plan to follow up with optimized implementations for these functions.
2025-12-04 08:46:22 +01:00
Matthias Krüger f6f7ddddd5 Rollup merge of #148918 - WaffleLapkin:tryfromwhattttt, r=jdonszelmann
Remove an outdated test

This... is a weird test.

It has two impls:
- `impl<T> From<Foo<T>> for Box<T>` (commented out, more on that later), and
- `impl<T> Into<Vec<T>> for Foo<T>`

The idea of that test is to show that the first impl doesn't compile, but the second does, thus `TryFrom` should be using `Into` and not `From` (because `Into` is more general, since the `From` impl doesn't compile).

However:
1. The types are different -- `Box` vs `Vec`, which is significant b/c `Box` is fundamental
2. The commented out impl actually compiles! (which wasn't detected b/c it's commented out :\ )

Here is a table for compilation of the impls:

|        | `Vec`        | `Box`          |
|--------|--------------|----------------|
| `From` | since 1.41.0 | never          |
| `Into` | always       | not since 1.28 |

[godbolt used to test this](https://godbolt.org/z/T38E3jGKa)

Order of events:
1. in `1.28` the `incoherent_fundamental_impls` lint becomes deny by default (this is *not* mentioned in the changelog yay)
2. `1.32` changed absolutely nothing, even though this version is credited in the test
3. the test was added (I'm not exactly sure when) (see https://github.com/rust-lang/rust/pull/56796)
4. in `1.41` coherence was relaxed to allow `From`+`Vec` to compile

To conclude: since `1.41` this test does nothing (and before that it was written in a way which did not detect this change). It looks to me like today (since `1.41`) we *could* bound `TryFrom` impl with `From` (but now it'd be a useless breaking change of course).

Am I missing anything? Is there a useful version of this test that could be written?
2025-12-03 13:05:13 +01:00
quaternic f49eaecca9 reorganize test contents and adjust generated inputs to reduce iterations 2025-12-03 10:08:29 +02:00
Matthias Krüger 45b2a711b1 Rollup merge of #148937 - joshtriplett:borrowed-buf-no-init-tracking, r=Amanieu
Remove initialized-bytes tracking from `BorrowedBuf` and `BorrowedCursor`

As discussed extensively in libs-api, the initialized-bytes tracking primarily benefits calls to `read_buf` that end up initializing the buffer and calling `read`, at the expense of calls to `read_buf` that *don't* need to initialize the buffer. Essentially, this optimizes for the past at the expense of the future. If people observe performance issues using `read_buf` (or something that calls it) with a given `Read` impl, they can fix those performance issues by implementing `read_buf` for that `Read`.

Update the documentation to stop talking about initialized-but-unfilled bytes.

Remove all functions that just deal with those bytes and their tracking, and remove usage of those methods.

Remove `BorrowedCursor::advance` as there's no longer a safe case for advancing within initialized-but-unfilled bytes. Rename `BorrowedCursor::advance_unchecked` to `advance`.

Update tests.

r? ``@Amanieu``
2025-12-03 07:36:12 +01:00
Matthias Krüger 38d5d2877e Rollup merge of #146436 - hkBst:slice-iter-1, r=joboet
Slice iter cleanup
2025-12-02 22:02:28 +01:00
Josh Triplett 382509988b Remove initialized-bytes tracking from BorrowedBuf and BorrowedCursor
As discussed extensively in libs-api, the initialized-bytes tracking
primarily benefits calls to `read_buf` that end up initializing the
buffer and calling `read`, at the expense of calls to `read_buf` that
*don't* need to initialize the buffer. Essentially, this optimizes for
the past at the expense of the future. If people observe performance
issues using `read_buf` (or something that calls it) with a given `Read`
impl, they can fix those performance issues by implementing `read_buf`
for that `Read`.

Update the documentation to stop talking about initialized-but-unfilled
bytes.

Remove all functions that just deal with those bytes and their tracking,
and remove usage of those methods.

Remove `BorrowedCursor::advance` as there's no longer a safe case for
advancing within initialized-but-unfilled bytes. Rename
`BorrowedCursor::advance_unchecked` to `advance`.

Update tests.
2025-12-02 01:32:27 -08:00
quaternic 3f1aa0b47e Additional test for uN::{gather,scatter}_bits 2025-12-02 09:20:47 +02: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
Waffle Lapkin a37873d7fb add a coretest checking TryInto/TryFrom impls 2025-12-01 16:42:52 +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
bors c86564c412 Auto merge of #149397 - matthiaskrgr:rollup-go79y6a, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - rust-lang/rust#147071 (constify from_fn, try_from_fn, try_map, map)
 - rust-lang/rust#148930 (tweak editor configs)
 - rust-lang/rust#149320 (-Znext-solver: normalize expected function input types when fudging)
 - rust-lang/rust#149363 (Port the `#![windows_subsystem]` attribute to the new attribute system)
 - rust-lang/rust#149378 (make run-make tests use 2024 edition by default)
 - rust-lang/rust#149381 (Add `impl TrustedLen` on `BTree{Map,Set}` iterators)
 - rust-lang/rust#149388 (remove session+blob decoder construction)
 - rust-lang/rust#149390 (`rust-analyzer` subtree update)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-11-27 19:24:40 +00:00
Matthias Krüger cdb678c165 Rollup merge of #148589 - yoshuawuyts:DropGuard-dismiss, r=joshtriplett
Rename `DropGuard::into_inner` to `DropGuard::dismiss`

Tracking issue: https://github.com/rust-lang/rust/issues/144426

One of the open questions blocking the stabilization of `DropGuard` is what to name the associated method that prevents the destructor from running, and returns the captured value. This method is currently called `into_inner`, but most people (including myself) feel like this would benefit from a method that calls more attention to itself.

This PR proposes naming this method `dismiss`, after the Linux kernel's [`ScopeGuard::dismiss`](https://rust.docs.kernel.org/kernel/types/struct.ScopeGuard.html#method.dismiss). Which crucially does not evoke images of violence or weaponry the way alternatives such as "disarm" or "defuse" do. And personally I enjoy the visual metaphor of "dismissing a guard" (e.g. a person keeping watch over something) - a job well done, they're free to go.

This PR also changes the signature from an static method to an instance method. This also matches the Linux kernel's API, and seems alright since `dismiss` is not nearly as ubiquitous as `into_inner`. This makes it more convenient to use, with a much lower risk of conflicting. Though in the rare case there might be ambiguity, the explicit notation is available as a fallback.

```rust
let x = DropGuard::into_inner(guard);  // ← current
let x = guard.dismiss();               // ← proposed
2025-11-27 15:59:11 +01:00
bendn e3a2c23e37 redo the drain 2025-11-27 20:18:13 +07: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
bendn 68abe69f13 iter::ArrayChunks::into_remainder ought not return option 2025-11-20 15:27:57 +07:00
Matthias Krüger 48fa9138c3 Rollup merge of #148798 - tamird:esc-single-quote, r=Amanieu
Match <OsString as Debug>::fmt to that of str

Fixes rust-lang/rust#114583.
2025-11-19 09:48:10 +01:00
Matthias Krüger 8b7479003b Rollup merge of #148797 - sorairolake:feature/non-zero-uint-bit-width, r=scottmcm
feat: Add `bit_width` for unsigned `NonZero<T>`

- Tracking issue: rust-lang/rust#142326

This pull request adds a method to the unsigned `NonZero<T>` that return the minimum number of bits required to represent a value.

This can be achieved by using the `get` method and the methods added in rust-lang/rust#142328, but I think adding the `NonZero::bit_width` method is useful because it accomplishes the same thing a little more succinctly.
2025-11-19 09:48:09 +01:00
Shun Sakai a25950dec6 feat: Change return type of NonZero::bit_width
Return `NonZero<u32>` instead of `u32`.
2025-11-19 03:17:38 +09:00
Tamir Duberstein 1cfd0b7c55 Match <OsString as Debug>::fmt to that of str
819247f1 changed <str as Debug>::fmt such that it does not escape single
quotes, but neglected to apply the same choice to OsString. This commit
does that.
2025-11-17 16:05:00 -05:00
Matthias Krüger 5dd82e8ed9 Rollup merge of #145610 - GrigorenkoPV:char_max_len, r=Amanieu
Stabilize `char_max_len`

Tracking issue: rust-lang/rust#121714

r? t-libs-api

`@rustbot` label +needs-fcp -T-libs +T-libs-api

Closes rust-lang/rust#121714
2025-11-17 18:07:31 +01:00
Ralf Jung 907fd85e16 const-eval: fix and re-enable pointer fragment support 2025-11-15 10:09:42 +01:00
Marijn Schouten a7ee7c8cbe slice iter: more cleanup 2025-11-14 17:45:23 +00:00
Pavel Grigorenko f9dcc6b21c Stabilize char_max_len 2025-11-14 18:23:19 +03:00
bors af5c5b74c8 Auto merge of #148587 - RalfJung:duration_from_nanos_u128, r=Mark-Simulacrum,oli-obk
stabilize duration_from_nanos_u128

libs-api FCP passed in https://github.com/rust-lang/rust/issues/139201.
Closes https://github.com/rust-lang/rust/issues/139201.

`@oli-obk` would you prefer if we did a const-hack to avoid allowing `const_trait_impl` here?
2025-11-13 14:48:17 +00:00
Stuart Cook 044c079b15 Rollup merge of #147771 - nxsaken:div_shlr_exact, r=dtolnay
Rename `*exact_{div,shr,shl}` to `*{div,shr,shl}_exact`

Related to rust-lang/rust#144336 and rust-lang/rust#139911, see https://github.com/rust-lang/rust/issues/139911#issuecomment-3406807537. I haven't touched the `exact_div`, `exact_udiv` and `exact_sdiv` intrinsics. Let me know if I should.
2025-11-11 21:09:34 +11:00
Shun Sakai f4efc370e6 feat: Add bit_width for unsigned NonZero<T> 2025-11-11 01:14:38 +09:00
Guillaume Gomez 6e14beae2a Allow function_casts_as_integer in coretest test 2025-11-10 16:38:28 +01:00
Ralf Jung b032fac34e stabilize duration_from_nanos_u128 2025-11-06 18:08:29 +01:00
Yosh 6f8a1a6082 Fix tests 2025-11-06 17:51:59 +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
nxsaken b76267672f Rename {i,u}N::*exact_div to *div_exact 2025-11-02 16:34:36 +04:00
bors 73e6c9ebd9 Auto merge of #147784 - nxsaken:div_exact_return_option, r=dtolnay
Return `Option` from `exact_div` and inherit overflow checks

According to https://github.com/rust-lang/rust/issues/139911#issuecomment-3404056127, `exact_div` should return `Option::None` if `self % rhs != 0`, panic if `rhs == 0`, and handle overflow conditionally (panic in debug, wrap in release).

rust-lang/rust#147771 should rename `exact_div` to `div_exact`.
2025-11-02 08:05:11 +00: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
Romain Perier 70876ee42b Unify and deduplicate max recip float tests 2025-10-25 17:57:06 +02:00