8932 Commits

Author SHA1 Message Date
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
Trevor Gross
fd06f6d658
Rollup merge of #142238 - RalfJung:nonnull_provenance, r=workingjubilee
stabilize nonnull_provenance

Fixes https://github.com/rust-lang/rust/issues/135243
FCP passed in https://github.com/rust-lang/rust/issues/135243
2025-06-09 12:17:55 -05:00
Trevor Gross
361423fc8a
Rollup merge of #141001 - hkBst:nonzero-char, r=dtolnay
Make NonZero<char> possible

I'd like to use `NonZero<char>` for representing units of CStr in https://github.com/rust-lang/literal-escaper
2025-06-09 12:17:53 -05:00
Trevor Gross
2f26913270
Rollup merge of #140767 - sayantn:stabilize-sha512, r=traviscross,tgross35
Stabilize `sha512`, `sm3` and `sm4` for x86

This PR stabilizes the feature flag `sha512_sm_x86` (tracking issue rust-lang/rust#126624).

# Public API
The 3 `x86` target features `sha512`, `sm3` and `sm4`, and the associated intrinsics in stdarch.

These target features are very specialized, and are only used to signal the presence of the corresponding CPU instruction. They don't have any nontrivial interaction with the ABI (contrary to something like AVX), and serve the only purpose of enabling 10 stdarch intrinsics, all of which have been implemented and propagated to rustc via a stdarch submodule update.

Also, these were added in LLVM17, and as the minimum LLVM required for rustc is LLVM19, we are safe in that front too!

# Associated PRs
 - rust-lang/rust#126704
 - rust-lang/stdarch#1592
 - rust-lang/stdarch#1790
 - rust-lang/rust#140389 (stdarch submodule update)
 - rust-lang/stdarch#1796 (stabilizing the runtime detection and intrinsics)
 - rust-lang/rust#141964 (stdarch submodule update for the stabilization of the runtime detection and intrinsics)

As all of the required tasks have been done (adding the target features to rustc, implementing their runtime detection in std_detect and implementing the associated intrinsics in core_arch), these target features can be stabilized now.

cc `@rust-lang/lang`
cc `@rust-lang/libs-api` for the intrinsics and runtime detection

I don't think anyone else worked on this feature, so no one else to ping, maybe cc `@Amanieu.` I will send the reference pr soon.
2025-06-09 12:17:52 -05:00
bors
14863ea077 Auto merge of #142242 - matthiaskrgr:rollup-1sgx0ji, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - rust-lang/rust#129121 (Stabilize `tcp_quickack`)
 - rust-lang/rust#142192 (De-duplicate f16 & f128 doctest attributes)
 - rust-lang/rust#142193 (add tests for pattern binding drop order edge cases)
 - rust-lang/rust#142222 (Dont make `ObligationCtxt`s with diagnostics unnecessarily)
 - rust-lang/rust#142228 (rustc-dev-guide subtree update)
 - rust-lang/rust#142231 (Run `calculate_matrix` job on `master` to cache citool builds)
 - rust-lang/rust#142232 (add `Cargo.lock` to CI-rustc allowed list for non-CI env)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-06-09 12:21:14 +00:00
Matthias Krüger
25de98fd41
Rollup merge of #142192 - Urgau:dedup-f16-f128-test-attrs, r=tgross35
De-duplicate f16 & f128 doctest attributes

Now that rustdoc supports `#[doc(test(attr(...)))]` at every level, thanks to https://github.com/rust-lang/rust/pull/140560, we can de-duplicate the f16 & f128 doctest attributes.

Unfortunately we can de-duplicate the `cfg`s attribute as rustdoc would complain about missing `main`, but it's already much better than before.

Addresses https://github.com/rust-lang/rust/pull/140323/files#r2062702761
r? `@tgross35`
2025-06-09 13:55:33 +02:00
Ralf Jung
3164ca8bb4 stabilize nonnull_provenance 2025-06-09 12:36:24 +02:00
Matthias Krüger
ad378be221
Rollup merge of #142160 - Urgau:check-cfg-bootstrap-only-rustc, r=Kobzol
Only allow `bootstrap` cfg in rustc & related

Fixes https://github.com/rust-lang/rust/issues/142150
r? bootstrap
2025-06-09 10:20:52 +02:00
Jubilee
faab021049
Rollup merge of #142162 - RalfJung:unsafe-pinned-get, r=workingjubilee,traviscross
UnsafePinned: update get() docs and signature to allow shared mutation

Follow-up to https://github.com/rust-lang/rust/pull/140638, making `get` consistent with the fact that there's an `UnsafeCell` inside this type now by returning `*mut T` instead of `*const T`.

Cc ``@rust-lang/libs-api``
Tracking issue: https://github.com/rust-lang/rust/issues/125735
2025-06-08 17:17:55 -07:00
Jubilee
840baa46ff
Rollup merge of #142053 - heiher:loong32-none, r=wesleywiser
Add new Tier-3 targets: `loongarch32-unknown-none*`

MCP: https://github.com/rust-lang/compiler-team/issues/865

NOTE: LoongArch32 ELF object support is available starting with object v0.37.0.
2025-06-08 17:17:53 -07:00
Jubilee Young
2e19658315 Remove rustc's notion of "preferred" alignment AKA __alignof
In PR 90877 T-lang decided not to remove `intrinsics::pref_align_of`.
However, the intrinsic and its supporting code
1.  is a nightly feature, so can be removed at compiler/libs discretion
2.  requires considerable effort in the compiler to support, as it
    necessarily complicates every single site reasoning about alignment
3.  has been justified based on relevance to codegen, but it is only a
    requirement for C++ (not C, not Rust) stack frame layout for AIX,
    in ways Rust would not consider even with increased C++ interop
4.  is only used by rustc to overalign some globals, not correctness
5.  can be adequately replaced by other rules for globals, as it mostly
    affects alignments for a few types under 16 bytes of alignment
6.  has only one clear benefactor: automating C -> Rust translation
    for GNU extensions like `__alignof`
7.  such code was likely intended to be `alignof` or `_Alignof`,
    because the GNU extension is a "false friend" of the C keyword,
    which makes the choice to support such a mapping very questionable
8.  makes it easy to do incorrect codegen in the compiler by its mere
    presence as usual Rust rules of alignment (e.g. `size == align * N`)
    do not hold with preferred alignment

The implementation is clearly damaging the code quality of the compiler.
Thus it is within the compiler team's purview to simply rip it out.
If T-lang wishes to have this intrinsic restored for c2rust's benefit,
it would have to use a radically different implementation that somehow
does not cause internal incorrectness.

Until then, remove the intrinsic and its supporting code, as one tool
and an ill-considered GCC extension cannot justify risking correctness.

Because we touch a fair amount of the compiler to change this at all,
and unfortunately the duplication of AbiAndPrefAlign is deep-rooted,
we keep an "AbiAlign" type which we can wean code off later.
2025-06-08 16:41:46 -07:00
bors
6ccd447603 Auto merge of #141700 - RalfJung:atomic-intrinsics-part2, r=bjorn3
Atomic intrinsics : use const generic ordering, part 2

This completes what got started in https://github.com/rust-lang/rust/pull/141507 by using a const generic for the ordering for all intrinsics. It is based on that PR; only the last commit is new.

Blocked on:
- https://github.com/rust-lang/rust/pull/141507
- https://github.com/rust-lang/rust/pull/141687
- https://github.com/rust-lang/stdarch/pull/1811
- https://github.com/rust-lang/rust/pull/141964

r? `@bjorn3`
2025-06-08 20:17:28 +00:00
Urgau
fdae3448ba De-duplicate f16 & f128 doctest attributes 2025-06-08 14:51:13 +02:00
Guillaume Gomez
aa940603f5
Rollup merge of #142154 - RalfJung:no-more-cfg-bootstrap, r=oli-obk
get rid of spurious cfg(bootstrap)

r? ```@oli-obk```
2025-06-07 22:23:00 +02:00
Guillaume Gomez
7b0eeab4c7
Rollup merge of #142065 - paolobarbolini:stabilize-const_eq_ignore_ascii_case, r=Mark-Simulacrum
Stabilize `const_eq_ignore_ascii_case`

Tracking issue: rust-lang/rust#131719
Closes rust-lang/rust#131719
FCP Completed: https://github.com/rust-lang/rust/issues/131719#issuecomment-2941829167
2025-06-07 22:22:57 +02:00
Guillaume Gomez
00db3457a6
Rollup merge of #141447 - y86-dev:option-layout-docs, r=RalfJung
Document representation of `Option<unsafe fn()>`

https://rust-lang.zulipchat.com/#narrow/channel/136281-t-opsem/topic/Option.20Layout.20with.20.60fn.60.20pointers/with/520055652
2025-06-07 22:22:56 +02:00
Ralf Jung
bd0a81ee82 centralize aliasing rules discussion in UnsafeCell docs 2025-06-07 21:57:45 +02:00
Ralf Jung
8808c9d34b intrinsics: use const generic to set atomic ordering 2025-06-07 21:45:58 +02:00
sayantn
632396ea01
Stabilize sha512_sm_x86, and the sha512, sm3 and sm4 target features 2025-06-07 23:27:15 +05:30
Urgau
9b1cd722ca Fix usage of bootstrap in core 2025-06-07 18:11:53 +02:00
Ralf Jung
bafe406711 UnsafePinned: update get() docs and signature to allow shared mutation 2025-06-07 15:43:15 +02:00
Marijn Schouten
a87cd55f8e Make NonZero<char> possible 2025-06-07 11:40:49 +00:00
Ralf Jung
6a6c595be6 get rid of spurious cfg(bootstrap) 2025-06-07 12:15:25 +02:00
Guillaume Gomez
6bbef981aa
Rollup merge of #142114 - GuillaumeGomez:u128-const, r=Urgau
Compute number of digits instead of relying on constant value for u128 display code

As discussed in https://github.com/rust-lang/rust/pull/142098/files#r2132084991, the code should reuse the same logic as the rest of file instead of using a constant value.

r? `@tamird`
2025-06-06 23:53:20 +02:00
Guillaume Gomez
28a2e1e9c9 Compute number of digits instead of relying on constant value for u128 display code 2025-06-06 14:28:37 +02:00
Tshepang Mbambo
0ffff4657a remove extraneous text
"Basic usage" implies there is an example that shows advanced usage
2025-06-06 06:39:51 +02:00
WANG Rui
38d69c3f57 Add new Tier-3 targets: loongarch32-unknown-none*
MCP: https://github.com/rust-lang/compiler-team/issues/865
2025-06-06 08:19:38 +08:00
LorrensP-2158466
00452bd783 change tests to use fixed constants to let them pass with miri 2025-06-05 16:22:13 +02:00
bors
0b20963d6b Auto merge of #142070 - matthiaskrgr:rollup-e7lxtuo, r=matthiaskrgr
Rollup of 6 pull requests

Successful merges:

 - rust-lang/rust#140638 (UnsafePinned: also include the effects of UnsafeCell)
 - rust-lang/rust#141777 (Do not run PGO/BOLT in x64 Linux alt builds)
 - rust-lang/rust#141938 (update rust offload bootstrap)
 - rust-lang/rust#141962 (rustc-dev-guide subtree update)
 - rust-lang/rust#141965 (`tests/ui`: A New Order [3/N])
 - rust-lang/rust#141970 (implement new `x` flag: `--skip-std-check-if-no-download-rustc`)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-06-05 13:44:43 +00:00
Matthias Krüger
2d7ebd3a99
Rollup merge of #140638 - RalfJung:unsafe-pinned-shared-aliased, r=workingjubilee
UnsafePinned: also include the effects of UnsafeCell

This tackles https://github.com/rust-lang/rust/issues/137750 by including an `UnsafeCell` in `UnsafePinned`, thus imbuing it with all the usual properties of interior mutability (no `noalias` nor `dereferenceable` on shared refs, special treatment by Miri's aliasing model). The soundness issue is not fixed yet because coroutine lowering does not use `UnsafePinned`.

The RFC said that `UnsafePinned` would not permit mutability on shared references, but since then, https://github.com/rust-lang/rust/issues/137750 has demonstrated that this is not tenable. In the face of those examples, I propose that we do the "obvious" thing and permit shared mutable state inside `UnsafePinned`. This seems loosely consistent with the fact that we allow going from `Pin<&mut T>` to `&T` (where the former can be aliased with other pointers that perform mutation, and hence the same goes for the latter) -- but the `as_ref` example shows that we in fact would need to add this `UnsafeCell` even if we didn't have a safe conversion to `&T`, since for the compiler and Miri, `&T` and `Pin<&T>` are basically the same type.

To make this possible, I had to remove the `Copy` and `Clone` impls for `UnsafePinned`.

Tracking issue: https://github.com/rust-lang/rust/issues/125735
Cc ``@rust-lang/lang`` ``@rust-lang/opsem``  ``@Sky9x``
I don't think this needs FCP since the type is still unstable -- we'll finally decide whether we like this approach when `UnsafePinned` is moved towards stabilization (IOW, this PR is reversible). However, I'd still like to make sure that the lang team is okay with the direction I am proposing here.
2025-06-05 12:21:29 +02:00
bors
c360e219f5 Auto merge of #135054 - cramertj:file-cstr, r=m-ou-se
Add Location::file_with_nul

This is useful for C/C++ APIs which expect the const char* returned from __FILE__ or std::source_location::file_name.

ACP: https://github.com/rust-lang/libs-team/issues/466
Tracking issue: https://github.com/rust-lang/rust/issues/141727
2025-06-05 10:21:20 +00:00
Paolo Barbolini
53c13011b7 Stabilize const_eq_ignore_ascii_case 2025-06-05 07:09:16 +00:00
Taylor Cramer
b541f93372 Add Location::file_with_nul
This is useful for C/C++ APIs which expect the const char* returned
from __FILE__ or std::source_location::file_name.
2025-06-04 09:23:05 -07:00
Matthias Krüger
005490cbbc
Rollup merge of #141893 - usamoi:lossless, r=tgross35
remove `f16: From<u16>`

it's not a lossless conversion

r? ``@tgross35``
2025-06-04 16:24:08 +02:00
Matthias Krüger
c5efc6aada
Rollup merge of #137306 - tgross35:remove-i128-u128-improper-ctypes, r=traviscross,workingjubilee
Remove `i128` and `u128` from `improper_ctypes_definitions`

Rust's 128-bit integers have historically been incompatible with C [1]. However, there have been a number of changes in Rust and LLVM that mean this is no longer the case:

* Incorrect alignment of `i128` on x86 [1]: adjusting Rust's alignment proposed at https://github.com/rust-lang/compiler-team/issues/683, implemented at https://github.com/rust-lang/rust/pull/116672.
* LLVM version of the above: resolved in LLVM, including ABI fix. Present in LLVM18 (our minimum supported version).
* Incorrect alignment of `i128` on 64-bit PowerPC, SPARC, and MIPS [2]: Rust's data layouts adjusted at https://github.com/rust-lang/rust/pull/132422, https://github.com/rust-lang/rust/pull/132741, https://github.com/rust-lang/rust/pull/134115.
* LLVM version of the above: done in LLVM 20 https://github.com/llvm/llvm-project/issues/102783.
* Incorrect return convention of `i128` on Windows: adjusted to match GCC and Clang at https://github.com/rust-lang/rust/pull/134290.

At https://github.com/rust-lang/lang-team/issues/255#issuecomment-2088855084, the lang team considered it acceptable to remove `i128` from `improper_ctypes_definitions` if the LLVM version is known to be compatible. Time has elapsed since then and we have dropped support for LLVM versions that do not have the x86 fixes, meaning a per-llvm-version lint should no longer be necessary. The PowerPC, SPARC, and MIPS changes only came in LLVM 20 but since Rust's datalayouts have also been updated to match, we will be using the correct alignment regardless of LLVM version.

`repr(i128)` was added to this lint in https://github.com/rust-lang/rust/pull/138282, but is also removed here.

Part of the decision is that `i128` should match `__int128` in C on platforms that provide it, which documentation is updated to indicate. We will not guarantee that `i128` matches `_BitInt(128)` since that can be different from `__int128`. Some platforms (usually 32-bit) do not provide `__int128`; if any ABIs are extended in the future to define it, we will need to make sure that our ABI matches.

Closes: https://github.com/rust-lang/rust/issues/134288

[1]: https://github.com/rust-lang/rust/issues/54341
[2]: https://github.com/rust-lang/rust/issues/128950
2025-06-04 07:54:31 +02:00
Matthias Krüger
3e7d5aaef5
Rollup merge of #136687 - joshtriplett:improve-display-and-fromstr-docs, r=Amanieu
Improve the documentation of `Display` and `FromStr`, and their interactions

In particular:
- `Display` is not necessarily lossless
- The output of `Display` might not be parseable by `FromStr`, and might
  not produce the same value if it is.
- Calling `.parse()` on the output of `Display` is usually a mistake
  unless a type's documented output and input formats match.
- The input formats accepted by `FromStr` depend on the type.

This documentation adds no API surface area and makes no guarantees about stability. To the best of my knowledge, everything it says is already established to be true. As such, I don't think it needs an FCP.
2025-06-04 07:54:30 +02:00
Josh Triplett
742014e7e3 Display: Rework explanation of FromStr/Display round-tripping
- Drop "usually a mistake"
- Add phrasing from `FromStr` about round-tripping, and about how the
  inability to round-trip may surprise users.
2025-06-03 15:41:47 -07:00
Josh Triplett
7ba5d26636 FromStr: Rework explanation of FromStr/Display round-tripping
- Drop the phrasing "usually a mistake".
- Mention that `Display` may not be lossless.
- Drop a misplaced parenthetical about round-tripping that didn't fit
  the paragraph it was in.
2025-06-03 15:41:47 -07:00
Josh Triplett
f412d05e50 Add some more description of interactions between Display and FromStr 2025-06-03 15:41:47 -07:00
Josh Triplett
252ad18415 Improve the documentation of Display and FromStr, and their interactions
In particular:
- `Display` is not necessarily lossless
- The output of `Display` might not be parseable by `FromStr`, and might
  not produce the same value if it is.
- Calling `.parse()` on the output of `Display` is usually a mistake
  unless a type's documented output and input formats match.
- The input formats accepted by `FromStr` depend on the type.
2025-06-03 15:41:47 -07:00
Matthias Krüger
c8a0f69d0e
Rollup merge of #141925 - cuviper:vestigial-bootstrap, r=workingjubilee
Remove bootstrap cfgs from library/

These `cfg(bootstrap)` are always false now that rust-lang/rust#119899 has landed, and likewise `cfg(not(bootstrap))` is always true. Therefore, we don't need to wait for the usual stage0 bump to clean these up.
2025-06-03 21:53:37 +02:00
Oli Scherer
5fbdfc3e10
Add iter macro
This adds an `iter!` macro that can be used to create movable
generators.

This also adds a yield_expr feature so the `yield` keyword can be used
within iter! macro bodies. This was needed because several unstable
features each need `yield` expressions, so this allows us to stabilize
them separately from any individual feature.

Co-authored-by: Oli Scherer <github35764891676564198441@oli-obk.de>
Co-authored-by: Jieyou Xu <jieyouxu@outlook.com>
Co-authored-by: Travis Cross <tc@traviscross.com>
2025-06-03 10:52:32 -07:00
bors
2f176126aa Auto merge of #141954 - matthiaskrgr:rollup-zptd6t9, r=matthiaskrgr
Rollup of 9 pull requests

Successful merges:

 - rust-lang/rust#141554 (Improve documentation for codegen options)
 - rust-lang/rust#141817 (rustc_llvm: add Windows system libs only when cross-compiling from Wi…)
 - rust-lang/rust#141843 (Add `visit_id` to ast `Visitor`)
 - rust-lang/rust#141881 (Subtree update of `rust-analyzer`)
 - rust-lang/rust#141898 ([rustdoc-json] Implement PartialOrd and Ord for rustdoc_types::Id)
 - rust-lang/rust#141921 (Disable f64 minimum/maximum tests for arm 32)
 - rust-lang/rust#141930 (Enable triagebot `[concern]` functionality)
 - rust-lang/rust#141936 (Decouple "reporting in deps" from `FutureIncompatibilityReason`)
 - rust-lang/rust#141949 (move `test-float-parse` tool into `src/tools` dir)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-06-03 09:51:59 +00:00
Matthias Krüger
2fa33b0624
Rollup merge of #141949 - onur-ozkan:move-test-float-parse, r=Kobzol
move `test-float-parse` tool into `src/tools` dir

Obviously `test-float-parse` is a tool like any other in `src/tools`.

cc `@tgross35`
2025-06-03 11:33:37 +02:00
Matthias Krüger
7e8a8c9cb1
Rollup merge of #141921 - ehuss:arm-min-max, r=tgross35
Disable f64 minimum/maximum tests for arm 32

This disables the f64 minimum/maximum tests for the arm-unknown-linux-gnueabihf job. The next release will be supporting cross-compiled doctests, and these tests fail on that platform.

It looks like this was just fixed via https://github.com/llvm/llvm-project/pull/142170, but I assume that will not trickle down to our copy of llvm in the next couple of weeks. Assuming that does get fixed when llvm is updated, then these can be removed.

cc https://github.com/rust-lang/rust/issues/141087
2025-06-03 11:33:35 +02:00
onur-ozkan
59fbe04a52 move test-float-parse tool into src/tools dir
Obviously `test-float-parse` is a tool like any other in `src/tools`.

Signed-off-by: onur-ozkan <work@onurozkan.dev>
2025-06-03 11:05:51 +03:00
Matthias Krüger
6a5459e186
Rollup merge of #141873 - neeko-cat:patch-1, r=tgross35
Fixed a typo in `ManuallyDrop`'s doc

I noticed a typo in `ManuallyDrop`'s documentation (someone wrote "iff" instead of "if"). I fixed it in this PR.
2025-06-03 07:03:44 +02:00
Josh Stone
c87b072952 Remove more library bootstrap 2025-06-02 14:46:19 -07:00
Josh Stone
19e02c8211 Remove bootstrap cfgs from library/ 2025-06-02 10:19:58 -07:00
Eric Huss
b0041b8a05 Disable f64 minimum/maximum tests for arm 32
This disables the f64 minimum/maximum tests for the
arm-unknown-linux-gnueabihf job. The next release will be supporting
cross-compiled doctests, and these tests fail on that platform.

It looks like this was just fixed via
https://github.com/llvm/llvm-project/pull/142170, but I assume that will
not trickle down to our copy of llvm in the next couple of weeks.
Assuming that does get fixed when llvm is updated, then these can be
removed.

cc https://github.com/rust-lang/rust/issues/141087
2025-06-02 09:08:01 -07:00