Commit Graph

9164 Commits

Author SHA1 Message Date
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
xizheyin
871397342c std: simplify NonNull variance documentation
Streamlined the explanation of covariance for `NonNull<T>`,
focusing on practical usage and reducing scary explanation.
Added a concise example for cases where invariance is required,
showing how to use `PhantomData<Cell<T>>

Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-06-04 01:39:02 +08: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
zachs18
c0851d76c9 Update ABI compatibility docs about null-pointer-optimized enums.
Add that the enum must be `#[repr(Rust)]` and not `#[repr(packed)]` or `#[repr(align)]` in order to be ABI-compatible with its null-pointer-optimized field.
2025-06-03 00:24:50 -05: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
Jakub Beránek
b2743c7fb1 Rollup merge of #141874 - usamoi:eps, r=tgross35
add f16_epsilon and f128_epsilon diagnostic items

cc https://github.com/rust-lang/rust/issues/116909
r? ``@tgross35``
2025-06-02 15:19:19 +02:00
Jakub Beránek
aeb72a0669 Rollup merge of #141858 - zacryol:spe-docs-typo, r=aDotInTheVoid
Fix typo in `StructuralPartialEq` docs

`equialent` => `equivalent`
2025-06-02 15:19:18 +02:00
usamoi
80e44de2d3 remove f16: From<u16> 2025-06-02 17:51:45 +08:00
usamoi
d948907f80 add f16_epsilon and f128_epsilon 2025-06-02 08:00:15 +08:00
neeko-cat
c5e758d3ad Fixed a typo in ManuallyDrop's doc 2025-06-02 01:55:29 +02:00
Guillaume Gomez
335232d958 Rollup merge of #141224 - RalfJung:no-objects, r=traviscross
terminology: allocated object → allocation

Rust does not have "objects" in memory so "allocated object" is a somewhat odd name. I am not sure where the term comes from. "object" has been used to refer to allocations already [in 1.0 docs](https://doc.rust-lang.org/1.0.0/std/primitive.pointer.html#method.offset); this was apparently later changed to "allocated object".

"Allocation" is already the terminology used in Miri and in the [UCG](https://rust-lang.github.io/unsafe-code-guidelines/glossary.html#allocation). We should properly move to that terminology, and avoid any confusion about whether Rust has an object memory model. (It does not. Memory contains untyped bytes.)

Cc ``@rust-lang/opsem`` ``@rust-lang/lang``
2025-06-01 19:35:42 +02:00
zacryol
33127afef0 Fix typo in StructuralPartialEq docs
`equialent` => `equivalent`
2025-06-01 08:15:00 -06:00
bors
337c11e593 Auto merge of #141842 - jhpratt:rollup-r7ldrl2, r=jhpratt
Rollup of 6 pull requests

Successful merges:

 - rust-lang/rust#141072 (Stabilize feature `result_flattening`)
 - rust-lang/rust#141215 (std: clarify Clone trait documentation about duplication semantics)
 - rust-lang/rust#141277 (Miri CI: test aarch64-apple-darwin in PRs instead of the x86_64 target)
 - rust-lang/rust#141521 (Add `const` support for float rounding methods)
 - rust-lang/rust#141812 (Fix "consider borrowing" for else-if)
 - rust-lang/rust#141832 (library: explain TOCTOU races in `fs::remove_dir_all`)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-06-01 01:02:51 +00:00
Jacob Pratt
ac49339e03 Rollup merge of #141521 - ruancomelli:const-float-rounding, r=RalfJung
Add `const` support for float rounding methods

# Add `const` support for float rounding methods

This PR makes the following float rounding methods `const`:

- `f64::{floor, ceil, trunc, round, round_ties_even}`
- and the corresponding methods for `f16`, `f32` and `f128`

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

## Procedure

I followed c09ed3e767 as closely as I could in making float methods `const`, and also received great guidance from https://internals.rust-lang.org/t/const-rounding-methods-in-float-types/22957/3?u=ruancomelli.

## Note

This is my first code contribution to the Rust project, so please let me know if I missed anything - I'd be more than happy to revise and learn more. Thank you for taking the time to review it!
2025-06-01 00:35:53 +02:00
Jacob Pratt
fa494d652d Rollup merge of #141215 - xizheyin:issue-141138, r=workingjubilee
std: clarify Clone trait documentation about duplication semantics

Closes rust-lang/rust#141138

The change explicitly explains that cloning behavior varies by type and clarifies that smart pointers (`Arc`, `Rc`) share the same underlying data. I've also added an example of cloning to Arc.
2025-06-01 00:35:50 +02:00
Jacob Pratt
241ec137fb Rollup merge of #141072 - Rynibami:stabilize-const-result-flatten, r=jhpratt
Stabilize feature `result_flattening`

Stabilizes the `Result::flatten` method

## Implementations

- [x] Implementation `Result::flatten`: https://github.com/rust-lang/rust/pull/70140
- [x] Implementation `const` `Result::flatten`: https://github.com/rust-lang/rust/pull/130692
- [x] Update stabilization attribute macros (this PR)

## Stabilization process

- [x] Created this PR [suggested](https://github.com/rust-lang/rust/issues/70142#issuecomment-2885044548) by ``@RalfJung``
- [x] FCP (haven't found any, is it applicable here?)
- [ ] Close issue rust-lang/rust#70142
2025-06-01 00:35:50 +02:00
bors
f0999ffdc4 Auto merge of #139118 - scottmcm:slice-get-unchecked-intrinsic, r=workingjubilee
`slice.get(i)` should use a slice projection in MIR, like `slice[i]` does

`slice[i]` is built-in magic, so ends up being quite different from `slice.get(i)` in MIR, even though they're both doing nearly identical operations -- checking the length of the slice then getting a ref/ptr to the element if it's in-bounds.

This PR adds a `slice_get_unchecked` intrinsic for `impl SliceIndex for usize` to use to fix that, so it no longer needs to do a bunch of lines of pointer math and instead just gets the obvious single statement.  (This is *not* used for the range versions, since `slice[i..]` and `slice[..k]` can't use the mir Slice projection as they're using fenceposts, not indices.)

I originally tried to do this with some kind of GVN pattern, but realized that I'm pretty sure it's not legal to optimize `BinOp::Offset` to `PlaceElem::Index` without an extremely complicated condition.  Basically, the problem is that the `Index` projection on a dereferenced slice pointer *cares about the metadata*, since it's UB to `PlaceElem::Index` outside the range described by the metadata.  But then you cast the fat pointer to a thin pointer then offset it, that *ignores* the slice length metadata, so it's possible to write things that are legal with `Offset` but would be UB if translated in the obvious way to `Index`.  Checking (or even determining) the necessary conditions for that would be complicated and error-prone, whereas this intrinsic-based approach is quite straight-forward.

Zero backend changes, because it just lowers to MIR, so it's already supported naturally by CTFE/Miri/cg_llvm/cg_clif.
2025-05-31 21:38:21 +00:00
Ralf Jung
f388c987cf terminology: allocated object → allocation 2025-05-31 22:49:14 +02: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
a2bf37e39e Rollup merge of #141112 - xizheyin:issue-141079, r=Mark-Simulacrum
std: note that `std::str::from_utf8*` functions are aliases to `<str>::from_utf8*` methods

Closes #141079

r? libs
2025-05-31 18:51:47 +02:00
xizheyin
3cba746b49 std: note that std::str::from_utf8* functions are aliases to std::<str>::from_utf8* methods
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-05-31 22:37:59 +08:00
bors
e0d014a3df Auto merge of #141678 - Kobzol:revert-141516, r=workingjubilee
Revert "increase perf of charsearcher for single ascii characters"

This reverts commit 245bf503e2 (PR https://github.com/rust-lang/rust/pull/141516).

It caused a large `doc` perf. regression in https://github.com/rust-lang/rust/pull/141605.
2025-05-31 08:11:06 +00:00
xizheyin
cea87ecad6 std: clarify Clone trait documentation about duplication semantics
This commit improves the Clone trait documentation to address confusion
around what "duplication" means for different types, especially for smart
pointers like Arc<Mutex<T>>.

Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-05-31 12:01:57 +08:00
Jubilee
ad884fa553 Rollup merge of #141609 - lolbinarycat:core-dedup-ptr-docs-139190, r=workingjubilee
core: begin deduplicating pointer docs

this also cleans up two inconsistancies:
1. both doctests on the ::add methods were actually calling the const version.
2. on of the ::offset methods was missing a line of clarification.

part of https://github.com/rust-lang/rust/issues/139190
2025-05-30 13:52:27 -07:00
Jubilee
a1d70ed5b0 Rollup merge of #141237 - Qelxiros:139911-exact-div, r=workingjubilee
Implement ((un)checked_)exact_div methods for integers

tracking issue: #139911

I see that there might still be some bikeshedding to be done, so if people want changes to this implementation, I'm happy to make those. I did also see that there was a previous attempt at this PR (#116632), but I'm not sure why it got closed.
2025-05-30 13:52:25 -07:00
Scott McMurray
4668124cc7 slice.get(i) should use a slice projection in MIR, like slice[i] does 2025-05-30 12:04:41 -07:00
Matthias Krüger
ad2d91ce11 Rollup merge of #141507 - RalfJung:atomic-intrinsics, r=bjorn3
atomic_load intrinsic: use const generic parameter for ordering

We have a gazillion intrinsics for the atomics because we encode the ordering into the intrinsic name rather than making it a parameter. This is particularly bad for those operations that take two orderings. Let's fix that!

This PR only converts `load`, to see if there's any feedback that would fundamentally change the strategy we pursue for the const generic intrinsics.

The first two commits are preparation and could be a separate PR if you prefer.

`@BoxyUwU` -- I hope this is a use of const generics that is unlikely to explode? All we need is a const generic of enum type. We could funnel it through an integer if we had to but an enum is obviously nicer...

`@bjorn3` it seems like the cranelift backend entirely ignores the ordering?
2025-05-30 07:01:30 +02:00
Guillaume Gomez
8c708a473d Rollup merge of #141715 - heiher:loong64-f32-midpoint, r=the8472
Add `loongarch64` with `d` feature to `f32::midpoint` fast path

This patch enables the optimized implementation of `f32::midpoint` for `loongarch64` targets that support the `d`feature. Targets with reliable 64-bit float support can safely use the faster and more accurate computation via `f64`, avoiding the fallback branchy version.
2025-05-29 17:03:01 +02:00
Trevor Gross
0cba7fb6f6 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 [3], 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 [4], 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
Closes: https://github.com/rust-lang/rust/issues/128950

[1]: https://github.com/rust-lang/rust/issues/54341
[2]: https://github.com/rust-lang/rust/issues/128950
[3]: https://github.com/rust-lang/lang-team/issues/255#issuecomment-2088855084
[4]: https://github.com/rust-lang/rust/pull/138282
2025-05-29 12:55:26 +00:00