300 Commits

Author SHA1 Message Date
Mara Bos
5b763fb1b7 Add test for new format_args!() temporary lifetimes. 2025-06-18 10:20:20 +02:00
Jakub Beránek
d9c83bb033 Rollup merge of #142373 - m-ou-se:debug-for-location, r=tgross35
Fix Debug for Location

Fixes https://github.com/rust-lang/rust/issues/142279
2025-06-16 14:31:11 +02:00
Mara Bos
5ac1cd9c7d Test Debug for Location. 2025-06-16 03:14:44 +00:00
Matthias Krüger
4cf4473b85 Rollup merge of #142243 - RalfJung:float-test-dedup, r=tgross35
float tests: deduplicate min, max, and rounding tests

Part of https://github.com/rust-lang/rust/issues/141726

Best reviewed commit-by-commit.

- Use `assert_biteq!` in the `mod.rs` tests. This requires some trickery to make shadowing macros with imports work.
- The min, max, minimum, maximum tests in `tests/floats/f*.rs` are entirely subsumed by what we already have in `tests/float/mod.rs`, so I just removed them.
- The rounding tests (floor etc) in `f*.rs` had more test points, so I copied them over. They didn't have `0.5` and `-0.5` though which seem like interesting points in particular regarding the sign of the resulting zero if that's what it sounds to, and they didn't max min/max/inf/nan tests, so this was really a merger of both tests.

r? ``@tgross35``
2025-06-14 11:27:11 +02:00
Matthias Krüger
db23a76217 Rollup merge of #141811 - mejrs:bye_locals, r=compiler-errors
Unimplement unsized_locals

Implements https://github.com/rust-lang/compiler-team/issues/630

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

Note that this just removes the feature, not the implementation, and does not touch `unsized_fn_params`. This is because it is required to support `Box<dyn FnOnce()>: FnOnce()`.

There may be more that should be removed (possibly in follow up prs)
- the `forget_unsized` function and `forget` intrinsic.
- the `unsized_locals` test directory; I've just fixed up the tests for now
- various codegen support for unsized values and allocas

cc ``@JakobDegen`` ``@oli-obk`` ``@Noratrieb`` ``@programmerjake`` ``@bjorn3``

``@rustbot`` label F-unsized_locals

Fixes rust-lang/rust#79409
2025-06-14 11:27:10 +02:00
Ralf Jung
25ec235b86 tweak runtime/const macro management 2025-06-13 10:22:56 +02:00
mejrs
c0e02e26b3 Unimplement unsized_locals 2025-06-13 01:16:36 +02:00
Tamir Duberstein
a82062055a Delegate <CStr as Debug> to ByteStr
This allows UTF-8 characters to be printed without escapes, rather than
just ASCII.
2025-06-12 12:53:14 -04:00
bors
14346303d7 Auto merge of #136594 - pascaldekloe:fmt-int128, r=tgross35
Faster fmt::Display of 128-bit integers, without unsafe pointer

In followup of #135265, hereby the 128-bit part.

* Batches per 16 instead of 19 digits
* Buffer access as array insteaf of unsafe pointer
* Added test coverage for i128 and u128

r? tgross35 ChrisDenton
2025-06-12 01:02:55 +00:00
Shun Sakai
199b808870 feat: Add bit_width for unsigned integer types 2025-06-11 11:15:37 +09:00
Pascal S. de Kloe
e9ebe25c66 format integer tests regrouped, min/max coverage and 128-bit coverage 2025-06-10 17:46:35 +02:00
bors
c6768de2d6 Auto merge of #138062 - LorrensP-2158466:miri-enable-float-nondet, r=RalfJung
Enable Non-determinism of float operations in Miri and change std tests

Links to [#4208](https://github.com/rust-lang/miri/issues/4208) and [#3555](https://github.com/rust-lang/miri/issues/3555) in Miri.

Non-determinism of floating point operations was disabled in rust-lang/rust#137594 because it breaks the tests and doc-tests in core/coretests and std. This PR enables some of them.

This pr includes the following changes:

- Enables the float non-determinism but with a lower relative error of 4ULP instead of 16ULP
- These operations now have a fixed output based on the C23 standard, except the pow operations, this is tracked in [#4286](https://github.com/rust-lang/miri/issues/4286#issue-3010677983)
- Changes tests that made incorrect assumptions about the operations, not to make that assumption anymore (from `assert_eq!` to `assert_approx_eq!`.
- Changed the doctests of the stdlib of these operations to compare against fixed constants instead of `f*::EPSILON`, which now succeed with Miri and `-Zmiri-many-seeds`
- Added a constant `APPROX_DELTA` in `std/tests/floats/f32.rs` which is used for approximation tests, but with a different value when run in Miri. This is to make these tests succeed.
- Added tests in the float tests of Miri to test the C23 behaviour.

Fixes https://github.com/rust-lang/miri/issues/4208
2025-06-09 21:21:58 +00:00
Ralf Jung
1b6bb4566d float midpoint tests: add missing NAN cases 2025-06-09 14:24:24 +02:00
Ralf Jung
2766b77f1e make the default float comparison tolerance type-dependent 2025-06-09 14:24:24 +02:00
Ralf Jung
79cb013b55 float tests: deduplicate min, max, and rounding tests 2025-06-09 14:24:12 +02:00
Ralf Jung
20cf8ca3f7 float tests: use assert_biteq in more places 2025-06-09 14:17:28 +02:00
Marijn Schouten
a87cd55f8e Make NonZero<char> possible 2025-06-07 11:40:49 +00:00
Jacob Pratt
0d2bf86284 Rollup merge of #141857 - RalfJung:coretests-floats, r=tgross35
coretests: move float tests from num to floats module and use a more flexible macro to generate them

This makes some progress on https://github.com/rust-lang/rust/issues/141726 by moving the float tests in `num` to `floats` and using a newer, more flexible macro to generate them. We also newly run these tests on f16 and f128 in const, and at runtime in Miri and for hosts where that works well enough.

I didn't yet deduplicate any tests or port the existing `floats::f*` tests to the macro, that can happen in a future PR.

try-job: x86_64-gnu-aux
2025-06-07 07:05:46 +02:00
LorrensP-2158466
00452bd783 change tests to use fixed constants to let them pass with miri 2025-06-05 16:22:13 +02:00
The 8472
61c2c1211f add comments to Zip unsoundness regression test 2025-06-05 01:28:55 +02:00
The 8472
cdeca5cbd3 fix Zip unsoundness (again)
Some history: The Zip TrustedRandomAccess specialization has tried
to emulate the side-effects of the naive implementation for a long time,
including backwards iteration. 82292¹ tried to fix unsoundness (82291¹) in that
side-effect-preservation code, but this introduced some panic-safety
unsoundness (86443¹), but the fix 86452¹ didn't fix it for nested Zip
iterators (137255¹).

Rather than piling yet another fix ontop of this heap of fixes this PR reduces
the number of cases in which side-effects will be preserved; the necessary
API guarantee change was approved in 83791¹ but we haven't made use of that
so far.

¹ see merge commit for linkfied issues.
2025-06-05 01:27:17 +02:00
Ralf Jung
7742d0e230 coretests: move float tests from num to floats module and use a more flexible macro to generate them 2025-06-04 16:32:17 +02:00
Matthias Krüger
5be375d0f8 Rollup merge of #141939 - Qelxiros:139911-exact-div-tests, r=workingjubilee
exact_div: add tests

tracking issue: rust-lang/rust#139911

I neglected to add tests in my last PR (rust-lang/rust#141237), so I've added them here.

r? ``@workingjubilee`` (Feel free to reroll, I just picked you since you reviewed the last one.)
2025-06-04 16:24:10 +02:00
Jeremy Smart
21a739fbf7 add tests for negative numbers 2025-06-03 21:02:04 -04:00
LorrensP-2158466
5bafe9d8fc Enable Float non-determinism in miri. Update and add tests and change
change tests in std, core and coretests.
2025-06-03 19:46:13 +02:00
Jeremy Smart
e87f1386d9 add tests 2025-06-02 22:57:16 -04:00
Josh Stone
19e02c8211 Remove bootstrap cfgs from library/ 2025-06-02 10:19:58 -07:00
Ruan Comelli
f8e97badb2 Add const support for float rounding methods
Add const support for the float rounding methods floor, ceil, trunc,
fract, round and round_ties_even.
This works by moving the calculation logic from

     src/tools/miri/src/intrinsics/mod.rs

into

     compiler/rustc_const_eval/src/interpret/intrinsics.rs.

All relevant method definitions were adjusted to include the `const`
keyword for all supported float types: f16, f32, f64 and f128.

The constness is hidden behind the feature gate

     feature(const_float_round_methods)

which is tracked in

     https://github.com/rust-lang/rust/issues/141555

This commit is a squash of the following commits:
- test: add tests that we expect to pass when float rounding becomes const
- feat: make float rounding methods `const`
- fix: replace `rustc_allow_const_fn_unstable(core_intrinsics)` attribute with `#[rustc_const_unstable(feature = "f128", issue = "116909")]` in `library/core/src/num/f128.rs`
- revert: undo update to `library/stdarch`
- refactor: replace multiple `float_<mode>_intrinsic` rounding methods with a single, parametrized one
- fix: add `#[cfg(not(bootstrap))]` to new const method tests
- test: add extra sign tests to check `+0.0` and `-0.0`
- revert: undo accidental changes to `round` docs
- fix: gate `const` float round method behind `const_float_round_methods`
- fix: remove unnecessary `#![feature(const_float_methods)]`
- fix: remove unnecessary `#![feature(const_float_methods)]` [2]
- revert: undo changes to `tests/ui/consts/const-eval/float_methods.rs`
- fix: adjust after rebase
- test: fix float tests
- test: add tests for `fract`
- chore: add commented-out `const_float_round_methods` feature gates to `f16` and `f128`
- fix: adjust NaN when rounding floats
- chore: add FIXME comment for de-duplicating float tests
- test: remove unnecessary test file `tests/ui/consts/const-eval/float_methods.rs`
- test: fix tests after upstream simplification of how float tests are run
2025-05-31 15:26:57 -03:00
Matthias Krüger
3ebdd59770 Rollup merge of #141669 - tgross35:float-test-cleanup, r=RalfJung
float: Replace some approximate assertions with exact

As was mentioned at [1], we currently use `assert_approx_eq` for testing
some math functions that guarantee exact results. Replace approximate
assertions with exact ones for the following:

* `ceil`
* `floor`
* `fract`
* `from_bits`
* `mul_add`
* `round_ties_even`
* `round`
* `trunc`

This likely wasn't done in the past to avoid writing out exact decimals
that don't match the intuitive answer (e.g. 1.3 - 1.0 = 0.300...004),
but ensuring our results are accurate seems more important here.

[1]: https://github.com/rust-lang/rust/pull/138087#issuecomment-2842069281

The first commit is a small bit of macro cleanup.

try-job: aarch64-gnu
try-job: x86_64-gnu-aux
2025-05-30 07:01:31 +02:00
Trevor Gross
70cce1c762 float: Use assert_biteq! where possible
`assert_eq!` ignores the sign of zero, but for any tests involving zeros
we do care about this sign. Replace `assert_eq!` with `assert_biteq!`
everywhere possible for float tests to ensure we don't miss this.
`assert_biteq!` is also updated to check equality on non-NaNs, to catch
the unlikely case that bitwise equality works but our `==`
implementation is broken.

There is one notable output change: we were asserting that
`(-0.0).fract()` and `(-1.0).fract()` both return -0.0, but both
actually return +0.0.
2025-05-29 21:13:26 +00:00
Trevor Gross
5446ba3c2d float: Enable some f16 and f128 rounding tests on miri
The rounding tests are now supported, so there is no longer any reason
to skip these.
2025-05-29 21:13:26 +00:00
Trevor Gross
9907c5a806 float: Replace some approximate assertions with exact
As was mentioned at [1], we currently use `assert_approx_eq` for testing
some math functions that guarantee exact results. Replace approximate
assertions with exact ones for the following:

* `ceil`
* `floor`
* `fract`
* `from_bits`
* `mul_add`
* `round_ties_even`
* `round`
* `trunc`

This likely wasn't done in the past to avoid writing out exact decimals
that don't match the intuitive answer (e.g. 1.3 - 1.0 = 0.300...004),
but ensuring our results are accurate seems more important here.

[1]: https://github.com/rust-lang/rust/pull/138087#issuecomment-2842069281
2025-05-29 21:13:26 +00:00
Trevor Gross
6a79b272ba float: Use a shared assert_biteq! macro for tests
Clean up the separate `assert_f{16,32,64,128}` macros with a single
`assert_biteq!` macro that works for all float widths.
2025-05-29 21:13:26 +00:00
Pavel Grigorenko
964eb82b63 Stabilize ip_from 2025-05-29 22:10:40 +03:00
Guillaume Gomez
cb7efc0cbd Rollup merge of #141676 - tgross35:f16-disable-total-cmp, r=workingjubilee
float: Disable `total_cmp` sNaN tests for `f16`

There is an LLVM bug with lowering of basic `f16` operations that mean a round trip via `__extendhfsf2` and `__truncsfhf2` may happen for simple `abs` calls or bitcasts [1]. This is problematic because the round trip quiets signaling NaNs. For most operations this is acceptable, but it is causing `total_cmp` tests to fail unless optimizations are enabled.

Disable `total_cmp` tests involving signaling NaNs until this issue is resolved.

Fixes: https://github.com/rust-lang/rustc_codegen_cranelift/issues/1578
Fixes: https://github.com/rust-lang/rust/issues/141503

[1]: https://github.com/llvm/llvm-project/issues/104915
2025-05-29 17:03:00 +02:00
Jacob Pratt
bf1343b963 Rollup merge of #141571 - RalfJung:float-tests, r=tgross35
coretests: extend and simplify float tests

Also de-duplicate tests by removing a ui test that duplicates the tests in core.
r? `@tgross35`
2025-05-29 04:50:47 +02:00
Trevor Gross
19fd098446 float: Disable total_cmp sNaN tests for f16
There is an LLVM bug with lowering of basic `f16` operations that mean a
round trip via `__extendhfsf2` and `__truncsfhf2` may happen for simple
`abs` calls or bitcasts [1]. This is problematic because the round trip
quiets signaling NaNs. For most operations this is acceptable, but it is
causing `total_cmp` tests to fail unless optimizations are enabled.

Disable `total_cmp` tests involving signaling NaNs until this issue is
resolved.

Fixes: https://github.com/rust-lang/rustc_codegen_cranelift/issues/1578
Fixes: https://github.com/rust-lang/rust/issues/141503

[1]: https://github.com/llvm/llvm-project/issues/104915
2025-05-28 06:49:04 +00:00
Ralf Jung
e0ff77aea5 coretests: add abs() and copysign() tests, and remove now-unnecessary ui test 2025-05-28 08:32:08 +02:00
Ralf Jung
2a9363e593 coretests: simplify test_float macro to derive more things from the type name 2025-05-28 08:30:14 +02:00
Tamir Duberstein
947be5f431 add CStr::display
The implementation delegates to `<ByteStr as Display>::fmt`.

Link: https://github.com/rust-lang/libs-team/issues/550
Link: https://github.com/rust-lang/rust/issues/139984.
2025-05-24 08:24:52 -04:00
bors
6eef33bb39 Auto merge of #137198 - tgross35:cfg-match-rename, r=Amanieu
Rename `cfg_match!` to `cfg_select!`

[`@Nemo157` pointed out](https://github.com/rust-lang/rust/issues/115585#issuecomment-2346307605) that `cfg_match!` syntax does not actually align well with match syntax, which is a possible source of confusion. The comment points out that usage is instead more similar to ecosystem `select!` macros. Rename `cfg_match!` to `cfg_select!` to match this.

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

[1]: https://github.com/rust-lang/rust/issues/115585#issuecomment-2346307605
2025-05-22 02:14:23 +00:00
Trevor Gross
999967a57d Rename cfg_match! to cfg_select!
At [1] it was pointed out that `cfg_match!` syntax does not actually
align well with match syntax, which is a possible source of confusion.
The comment points out that usage is instead more similar to ecosystem
`select!` macros. Rename `cfg_match!` to `cfg_select!` to match this.

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

[1]: https://github.com/rust-lang/rust/issues/115585#issuecomment-2346307605
2025-05-20 21:16:23 +00:00
Daniel McNab
f6709bb683 core_float_math: Move functions to math folder
When these functions were added in
https://github.com/rust-lang/rust/pull/138087
It made a relatively common pattern for emulating
these functions using an extension trait (which
internally uses `libm`) much more fragile.
If `core::f32` happened to be imported by the user
(to access a constant, say), then that import in
the module namespace would take precedence over
`f32` in the type namespace for resolving these
functions, running headfirst into the stability
attribute.

We ran into this in Color -
https://github.com/linebender/color - and chose to
release the remedial 0.3.1 and 0.2.4, to allow
downstream crates to build on `docs.rs`.
As these methods are perma-unstable, moving them
into a new module should not have any long-term
concerns, and ensures that this breakage doesn't
adversely impact anyone else.
2025-05-20 16:41:43 +01:00
bors
4d051fb306 Auto merge of #127013 - tgross35:f16-format-parse, r=Mark-Simulacrum
Add `f16` formatting and parsing

Use the same algorithms as for `f32` and `f64` to implement `f16` parsing and printing.

try-job: x86_64-gnu-aux
2025-05-18 20:38:01 +00:00
Trevor Gross
977d841869 float: Add tests for f16 conversions to and from decimal
Extend the existing tests for `f32` and `f64` with versions that include
`f16`'s new printing and parsing implementations.

Co-authored-by: Speedy_Lex <alex.ciocildau@gmail.com>
2025-05-18 16:51:28 +00:00
León Orell Valerian Liehr
5a55870aa1 Rollup merge of #140924 - Urgau:f32_f64_const_tests, r=Mark-Simulacrum
Make some `f32`/`f64` tests also run in const-context
2025-05-18 11:03:45 +02:00
bors
777d372772 Auto merge of #138087 - tgross35:core-float-math, r=Amanieu
Initial implementation of `core_float_math`

Since [1], `compiler-builtins` makes a certain set of math symbols
weakly available on all platforms. This means we can begin exposing some
of the related functions in `core`, so begin this process here.

It is not possible to provide inherent methods in both `core` and `std`
while giving them different stability gates, so standalone functions are
added instead. This provides a way to experiment with the functionality
while unstable; once it is time to stabilize, they can be converted to
inherent.

For `f16` and `f128`, everything is unstable so we can move the inherent
methods.

The following are included to start:

* floor
* ceil
* round
* round_ties_even
* trunc
* fract
* mul_add
* div_euclid
* rem_euclid
* powi
* sqrt
* abs_sub
* cbrt

These mirror the set of functions that we have in `compiler-builtins`
since [1], with the exception of `powi` that has been there longer.

Details for each of the changes is in the commit messages.

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

[1]: https://github.com/rust-lang/compiler-builtins/pull/763

try-job: aarch64-gnu
tru-job: armhf-gnu
try-job: i686-msvc-1
try-job: test-various
try-job: x86_64-mingw-1
try-job: x86_64-mingw-2
2025-05-17 19:31:39 +00:00
Matthias Krüger
642cd65ab2 Rollup merge of #140957 - JulianKnodt:array_must_use, r=Mark-Simulacrum
Add `#[must_use]` to Array::map

The output of Array::map is intended to be an array of the same size, and does not modify the original in place nor is it intended for side-effects. Thus, under normal circumstances it should be consumed.

See [discussion](https://internals.rust-lang.org/t/array-map-annotate-with-must-use/22813/26).

Attaching to tracking issue #75243
2025-05-17 10:33:09 +02:00
Trevor Gross
65117eeda8 Skip {f32,f64}::mul_add tests on MinGW
Per [1], MinGW has an incorrect fma implementation. This showed up in
tests run with cranelift after adding float math operations to `core`.
Presumably we hadn't noticed this when running tests with LLVM because
LLVM was constant folding the result away.

Rust issue: https://github.com/rust-lang/rust/issues/140515

[1]: https://sourceforge.net/p/mingw-w64/bugs/848/
2025-05-14 14:30:03 +00:00
Trevor Gross
2b9256e1c8 Move applicable float tests from coretests back to std
The previous commit moved all test files from `std` to `core` so git
understands the move. Not all functionality is actually testable in
`core`, however, so perform move the relevant portions back. Changes
from inherent to module methods is also done since this is the form of
math operations available in `core` (as `core_float_math`).
2025-05-14 14:29:58 +00:00