Commit Graph

275 Commits

Author SHA1 Message Date
Matthias Krüger
32c045ecd1 Rollup merge of #146488 - ferrocene:pvdrz/improve-ptr-coverage, r=Mark-Simulacrum
Improve `core::ptr` coverage

This PR improves the `core::ptr` coverage by adding a new test to `coretests` for the `<*const T>::is_aligned_to` method.

r? libs
2025-09-15 06:03:48 +02: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
Matthias Krüger
fa63dbf301 Rollup merge of #146284 - Kivooeo:blazing-fast-division-bignum, r=Mark-Simulacrum
Remove `div_rem` from `core::num::bignum`

This fixes very old fixme that sounds like this

```
Stupid slow base-2 long division taken from
https://en.wikipedia.org/wiki/Division_algorithm
FIXME use a greater base ($ty) for the long division.
```

By deleting this method since it was never used
2025-09-15 06:03:45 +02:00
Jana Dönszelmann
ec0f3bd2ed Rollup merge of #146481 - ferrocene:pvdrz/improve-hash-coverage, r=jhpratt
Improve `core::hash` coverage

This PR improves the `core::hash` coverage by adding a new test to `coretests` and extending one of the existing tests to use 128-bit integers

r? libs
2025-09-13 02:40: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
Jana Dönszelmann
e4dbbbd322 Rollup merge of #146452 - ferrocene:pvdrz/improve-alloc-coverage, r=tgross35
Improve `alloc::Layout` coverage

This PR improves the `core::alloc` coverage by adding a new test to `coretests` that cover the `Layout` methods when they error.

Tracking issue: https://github.com/rust-lang/rust/issues/55724
2025-09-13 02:40:45 +02:00
Christian Poveda
87ae4dbf5c Improve core::ptr coverage 2025-09-12 14:41:26 -05:00
Christian Poveda
79643ad48a Improve core::hash coverage 2025-09-12 13:54:15 -05: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
Christian Poveda
18059a0053 Improve core::alloc coverage 2025-09-12 10:49:52 -05:00
Evgenii Zheltonozhskii
ff9b1c1d28 Constify Eq, Ord, PartialOrd 2025-09-12 12:39:31 +03:00
Stuart Cook
5258dfc0b7 Rollup merge of #146425 - ferrocene:pvdrz/improve-array-coverage, r=workingjubilee
Improve `core::array` coverage

This PR improves the `core::array` coverage by adding new tests to `coretests`
2025-09-11 14:06:33 +10:00
Stuart Cook
81840271c3 Rollup merge of #146424 - ferrocene:pvdrz/improve-ops-coverage, r=workingjubilee
Improve `core::ops` coverage

This PR improves the `core::ops` coverage by adding new tests to `coretests`
2025-09-11 14:06:32 +10:00
Stuart Cook
c69a792137 Rollup merge of #146380 - rperier:unify_and_dedup_bits_conv_float_tests, r=tgross35
Unify and deduplicate bits conv float tests

cc rust-lang/rust#141726

This is a proposal to unify and deduplicate the bits conv tests for f16, f32, f64 and f128
2025-09-11 14:06:30 +10:00
Christian Poveda
a7528e7ec3 Improve core::array coverage 2025-09-10 17:25:24 -05:00
Christian Poveda Ruiz
789c8408ec Update library/coretests/tests/ops.rs
Co-authored-by: Jubilee <workingjubilee@gmail.com>
2025-09-10 16:50:45 -05:00
Christian Poveda
5f2b04652f Improve core::ops coverage 2025-09-10 16:32:04 -05:00
Romain Perier
b1c4e19e13 Unify and deduplicate bits conv float tests 2025-09-10 14:25:36 +02:00
Ralf Jung
aed0ed4c93 const-eval: disable pointer fragment support 2025-09-08 13:22:52 +02:00
Kivooeo
a2d66db9ba remove unsused div_rem method from bignum 2025-09-07 17:21:47 +00:00
Trevor Gross
ebde667698 Rollup merge of #145940 - pascaldekloe:int-exp-tune, r=tgross35
single buffer for exponent fmt of integers

No need for fragmented buffers when formatting.

```
orig.txt: fmt::write_i128_exp                                                  143.39ns/iter      +/- 0.32
orig.txt: fmt::write_i64_exp                                                    68.72ns/iter      +/- 0.03
new.txt:  fmt::write_i128_exp                                                  138.29ns/iter      +/- 0.50
new.txt:  fmt::write_i64_exp                                                    58.93ns/iter      +/- 4.62
```

This patch fully eliminates unsafe pointer use (after rust-lang/rust#135265 and rust-lang/rust#136594).

    r? libs
2025-09-06 14:39:04 -04:00
Trevor Gross
db5cc29d4f Rollup merge of #146152 - rperier:unify_and_dedup_algebraic_float_tests, r=tgross35
Unify and deduplicate algebraic float tests

cc rust-lang/rust#141726

This is a proposal to unify and deduplicate the algebraic tests for f16, f32, f64 and f128
2025-09-05 01:53:21 -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
Romain Perier
4e872375d4 Unify and deduplicate algebraic float tests 2025-09-03 14:39:50 +02: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
1d520e2694 Rollup merge of #145468 - karolzwolak:float-tests-dedup, r=tgross35
dedup recip, powi, to_degrees, and to_radians float tests

Deduplicates recip, powi, to_degrees, and to_radians float tests.
I had to fiddle and slightly increase the tolerances for a few comparisons, so maybe not all of the tests are worth deduplicating.

Part of rust-lang/rust#141726.
Best reviewed commit-by-commit.

r? `@tgross35`
2025-09-01 17:35:02 +10:00
Karol Zwolak
9028efcf2e dedup to_radians float test 2025-08-31 18:20:49 +02:00
Karol Zwolak
c81a8a89ee dedup to_degrees float test 2025-08-31 18:19:05 +02:00
Karol Zwolak
e10e6d78ac dedup powi float test 2025-08-31 18:16:00 +02:00
Matthias Krüger
59a645ac25 Rollup merge of #145174 - 197g:issue-145148-select-unpredictable-drop, r=joboet
Ensure consistent drop for panicking drop in hint::select_unpredictable

There are a few alternatives to the implementation. The principal problem is that the selected value must be owned (in the sense of having a drop flag of sorts) when the unselected value is dropped, such that panic unwind goes through the drop of both. This ownership must then be passed on in return when the drop went smoothly.

The basic way of achieving this is by extracting the selected value first, at the cost of relying on the optimizer a little more for detecting the copy as constructing the return value despite having a place in the body. Unfortunately, that causes LLVM to discard the !unpredictable annotation (for some reason that is beyond my comprehension of LLVM).

<details>
<summary>Extract from the build log showing an unannotated select being used</summary>

```
2025-08-09T16:51:06.8790764Z            39: define noundef i64 `@test_int2(i1` noundef zeroext %p, i64 noundef %a, i64 noundef %b) unnamed_addr #0 personality ptr `@rust_eh_personality` {
2025-08-09T16:51:06.8791368Z check:47'0                                  X~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: no match found
2025-08-09T16:51:06.8791700Z            40: start:
2025-08-09T16:51:06.8791858Z check:47'0     ~~~~~~~
2025-08-09T16:51:06.8792043Z            41:  %ret.i = select i1 %p, i64 %a, i64 %b
2025-08-09T16:51:06.8792293Z check:47'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2025-08-09T16:51:06.8792686Z check:47'1               ?                             possible intended match
2025-08-09T16:51:06.8792946Z            42:  ret i64 %ret.i
2025-08-09T16:51:06.8793127Z check:47'0     ~~~~~~~~~~~~~~~~
```

</details>

So instead, this PR includes a guard to drop the selected `MaybeUnit<T>` which is active only for the section where the unselected value is dropped. That leaves the code for selecting the result intact leading to the expected ir. That complicates the 'unselection' process a little bit since we require _both_ values as a result of that intrinsic call. Since the arguments alias, this portion as well as the drop guard uses raw pointers.

Closes: rust-lang/rust#145148
Prior: rust-lang/rust#139977
2025-08-31 13:40:35 +02:00
Karol Zwolak
6ebd009d47 dedup recip float test
I left the additional asserts on {f16, f128}::MAX.recip() in a new
test_max_recip tests.
2025-08-30 14:54:41 +02:00
Aurelia Molzer
539f8400e7 Clarify panic-drop test for select_unpredictable 2025-08-30 13:01:32 +02: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
Stuart Cook
ef50370ec1 Rollup merge of #144275 - Qelxiros:saturating-arithmetic, r=tgross35
implement Sum and Product for Saturating(u*)

ACP: rust-lang/libs-team#604

`@rustbot` label +needs-fcp
2025-08-29 12:54:09 +10:00
Jeremy Smart
1a33d628df implement Sum and Product for Saturating(u*) 2025-08-28 18:38:53 -04: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
Matthias Krüger
62e5341661 Rollup merge of #145335 - clarfonthey:wtf8-core-alloc, r=Mark-Simulacrum
Move WTF-8 code from std into core and alloc

This is basically a small portion of rust-lang/rust#129411 with a smaller scope. It *does not*\* affect any public APIs; this code is still internal to the standard library. It just moves the WTF-8 code into `core` and `alloc` so it can be accessed by `no_std` crates like `backtrace`.

> \* The only public API this affects is by adding a `Debug` implementation to `std::os::windows::ffi::EncodeWide`, which was not present before. This is due to the fact that `core` requires `Debug` implementations for all types, but `std` does not (yet) require this. Even though this was ultimately changed to be a wrapper over the original type, not a re-export, I decided to keep the `Debug` implementation so it remains useful.

Like we do with ordinary strings, the tests are still located entirely in `alloc`, rather than splitting them into `core` and `alloc`.

----

Reviewer note: for ease of review, this is split into three commits:

1. Moving the original files into their new "locations"
2. Actually modifying the code to compile.
3. Removing aesthetic changes that were made so that the diff for commit 2 was readable.

You can review commits 1 and 3 to verify these claims, but commit 2 contains the majority of the changes you should care about.

----

API changes: `impl Debug for std::os::windows::ffi::EncodeWide`
2025-08-27 07:45:56 +02:00
Jacob Pratt
dbc38eed1d Rollup merge of #132087 - ijchen:issue-131770-fix, r=dtolnay
Fix overly restrictive lifetime in `core::panic::Location::file` return type

Fixes #131770 by relaxing the lifetime to match what's stored in the struct. See that issue for more details and discussion.

Since this is a breaking change, I think a crater run is in order. Since this change should only have an effect at compile-time, I think just a check run is sufficient.
2025-08-22 22:00:44 -04:00
Pascal S. de Kloe
2143a3f0c2 benchmarks for exponent fmt of integers 2025-08-22 17:40:48 +02:00
Karl Meakin
377a0c88a9 Consolidate panicking functions in slice/index.rs
Consolidate all the panicking functions in `slice/index.rs` to use a single
`slice_index_fail` function, similar to how it is done in `str/traits.rs`.
2025-08-21 11:07:25 +01: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
许杰友 Jieyou Xu (Joe)
4327e69030 Rollup merge of #143730 - pascaldekloe:fmt-radix-trim, r=tgross35
fmt of non-decimal radix untangled

Have the implementation match its decimal counterpart.

* Digit table instead of conversion functions
* Correct buffer size per radix
* Elimination of dead code for negative
* No trait abstraction for integers

#### Original Performance
```
    fmt::write_10ints_bin                                                393.03ns/iter      +/- 1.41
    fmt::write_10ints_hex                                                316.84ns/iter      +/- 1.49
    fmt::write_10ints_oct                                                327.16ns/iter      +/- 0.46
```

#### Patched Performance
```
    fmt::write_10ints_bin                                                392.31ns/iter      +/- 3.05
    fmt::write_10ints_hex                                                302.41ns/iter      +/- 5.48
    fmt::write_10ints_oct                                                322.01ns/iter      +/- 3.82
```

r? tgross35
2025-08-19 19:42:03 +08: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