Skip to content

Commit 8aa5222

Browse files
authored
Rollup merge of rust-lang#138285 - beetrees:repr128-stable, r=traviscross,bjorn3
Stabilize `repr128` ## Stabilisation report The `repr128` feature ([tracking issue](rust-lang#56071)) allows the use of `#[repr(u128)]` and `#[repr(i128)]` on enums in the same way that other primitive representations such as `#[repr(u64)]` can be used. For example: ```rust #[repr(u128)] enum Foo { One = 1, Two, Big = u128::MAX, } #[repr(i128)] enum Bar { HasThing(u16) = 42, HasSomethingElse(i64) = u64::MAX as i128 + 1, HasNothing, } ``` This is the final part of adding 128-bit integers to Rust ([RFC 1504](https://rust-lang.github.io/rfcs/1504-int128.html)); all other parts of 128-bit integer support were stabilised in rust-lang#49101 back in 2018. From a design perspective, `#[repr(u128)]`/`#[repr(i128)]` function like `#[repr(u64)]`/`#[repr(i64)]` but for 128-bit integers instead of 64-bit integers. The only differences are: - FFI safety: as `u128`/`i128` are not currently considered FFI safe, neither are `#[repr(u128)]`/`#[repr(i128)]` enums (I discovered this wasn't the case while drafting this stabilisation report, so I have submitted rust-lang#138282 to fix this). - Debug info: while none of the major debuggers currently support 128-bit integers, as of LLVM 20 `rustc` will emit valid debuginfo for both DWARF and PDB (PDB makes use of the same natvis that is also used for all enums with fields, whereas DWARF has native support). Tests for `#[repr(u128)]`/`#[repr(i128)]` enums include: - [ui/enum-discriminant/repr128.rs](https://github.com/rust-lang/rust/blob/385970f0c1fd0c09bac426b02f38300c0b1ba9a2/tests/ui/enum-discriminant/repr128.rs): checks that 128-bit enum discriminants have the correct values. - [debuginfo/msvc-pretty-enums.rs](https://github.com/rust-lang/rust/blob/385970f0c1fd0c09bac426b02f38300c0b1ba9a2/tests/debuginfo/msvc-pretty-enums.rs): checks the PDB debuginfo is correct. - [run-make/repr128-dwarf](https://github.com/rust-lang/rust/blob/385970f0c1fd0c09bac426b02f38300c0b1ba9a2/tests/run-make/repr128-dwarf/rmake.rs): checks the DWARF debuginfo is correct. Stabilising this feature does not require any changes to the Rust Reference as [the documentation on primitive representations](https://doc.rust-lang.org/nightly/reference/type-layout.html#r-layout.repr.primitive.intro) already includes `u128` and `i128`. Closes rust-lang#56071 Closes rust-lang/reference#1368 r? lang `@rustbot` label +I-lang-nominated +T-lang
2 parents 709d262 + 467eeab commit 8aa5222

File tree

32 files changed

+143
-277
lines changed

32 files changed

+143
-277
lines changed

compiler/rustc_error_codes/src/error_codes/E0658.md

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@ An unstable feature was used.
33
Erroneous code example:
44

55
```compile_fail,E0658
6-
#[repr(u128)] // error: use of unstable library feature 'repr128'
7-
enum Foo {
8-
Bar(u64),
9-
}
6+
use std::intrinsics; // error: use of unstable library feature `core_intrinsics`
107
```
118

129
If you're using a stable or a beta version of rustc, you won't be able to use
@@ -17,12 +14,9 @@ If you're using a nightly version of rustc, just add the corresponding feature
1714
to be able to use it:
1815

1916
```
20-
#![feature(repr128)]
17+
#![feature(core_intrinsics)]
2118
22-
#[repr(u128)] // ok!
23-
enum Foo {
24-
Bar(u64),
25-
}
19+
use std::intrinsics; // ok!
2620
```
2721

2822
[rustup]: https://rust-lang.github.io/rustup/concepts/channels.html

compiler/rustc_feature/src/accepted.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,8 @@ declare_features! (
360360
(accepted, relaxed_adts, "1.19.0", Some(35626)),
361361
/// Lessens the requirements for structs to implement `Unsize`.
362362
(accepted, relaxed_struct_unsize, "1.58.0", Some(81793)),
363+
/// Allows the `#[repr(i128)]` attribute for enums.
364+
(accepted, repr128, "CURRENT_RUSTC_VERSION", Some(56071)),
363365
/// Allows `repr(align(16))` struct attribute (RFC 1358).
364366
(accepted, repr_align, "1.25.0", Some(33626)),
365367
/// Allows using `#[repr(align(X))]` on enums with equivalent semantics

compiler/rustc_feature/src/unstable.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -621,8 +621,6 @@ declare_features! (
621621
(incomplete, ref_pat_eat_one_layer_2024_structural, "1.81.0", Some(123076)),
622622
/// Allows using the `#[register_tool]` attribute.
623623
(unstable, register_tool, "1.41.0", Some(66079)),
624-
/// Allows the `#[repr(i128)]` attribute for enums.
625-
(incomplete, repr128, "1.16.0", Some(56071)),
626624
/// Allows `repr(simd)` and importing the various simd intrinsics.
627625
(unstable, repr_simd, "1.4.0", Some(27731)),
628626
/// Allows bounding the return type of AFIT/RPITIT.

compiler/rustc_hir_analysis/src/check/check.rs

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use rustc_middle::middle::resolve_bound_vars::ResolvedArg;
1818
use rustc_middle::middle::stability::EvalResult;
1919
use rustc_middle::ty::error::TypeErrorToStringExt;
2020
use rustc_middle::ty::layout::{LayoutError, MAX_SIMD_LANES};
21-
use rustc_middle::ty::util::{Discr, IntTypeExt};
21+
use rustc_middle::ty::util::Discr;
2222
use rustc_middle::ty::{
2323
AdtDef, BottomUpFolder, GenericArgKind, RegionKind, TypeFoldable, TypeSuperVisitable,
2424
TypeVisitable, TypeVisitableExt, fold_regions,
@@ -1385,19 +1385,6 @@ fn check_enum(tcx: TyCtxt<'_>, def_id: LocalDefId) {
13851385
);
13861386
}
13871387

1388-
let repr_type_ty = def.repr().discr_type().to_ty(tcx);
1389-
if repr_type_ty == tcx.types.i128 || repr_type_ty == tcx.types.u128 {
1390-
if !tcx.features().repr128() {
1391-
feature_err(
1392-
&tcx.sess,
1393-
sym::repr128,
1394-
tcx.def_span(def_id),
1395-
"repr with 128-bit type is unstable",
1396-
)
1397-
.emit();
1398-
}
1399-
}
1400-
14011388
for v in def.variants() {
14021389
if let ty::VariantDiscr::Explicit(discr_def_id) = v.discr {
14031390
tcx.ensure_ok().typeck(discr_def_id.expect_local());

src/doc/unstable-book/src/language-features/repr128.md

Lines changed: 0 additions & 18 deletions
This file was deleted.

src/tools/clippy/tests/ui/auxiliary/proc_macro_attr.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
#![feature(repr128, proc_macro_hygiene, proc_macro_quote, box_patterns)]
2-
#![allow(incomplete_features)]
1+
#![feature(proc_macro_hygiene, proc_macro_quote, box_patterns)]
32
#![allow(clippy::useless_conversion, clippy::uninlined_format_args)]
43

54
extern crate proc_macro;

src/tools/clippy/tests/ui/auxiliary/proc_macro_derive.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
#![feature(repr128, proc_macro_quote, proc_macro_span)]
2-
#![allow(incomplete_features)]
1+
#![feature(proc_macro_quote, proc_macro_span)]
32
#![allow(clippy::field_reassign_with_default)]
43
#![allow(clippy::eq_op)]
54
#![allow(clippy::literal_string_with_formatting_args)]

src/tools/clippy/tests/ui/cast.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
//@no-rustfix: only some diagnostics have suggestions
22

3-
#![feature(repr128)]
4-
#![allow(incomplete_features)]
53
#![warn(
64
clippy::cast_precision_loss,
75
clippy::cast_possible_truncation,

0 commit comments

Comments
 (0)