From e5f0680ee2f1e436bd8a781df2c3fcd20cc08e99 Mon Sep 17 00:00:00 2001 From: Scott McMurray Date: Sat, 18 Jul 2026 03:28:39 -0700 Subject: [PATCH] Stop passing the discriminant as `i128` when `Discr` makes it as `u128` --- compiler/rustc_abi/src/layout.rs | 8 ++++---- compiler/rustc_ty_utils/src/layout.rs | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/compiler/rustc_abi/src/layout.rs b/compiler/rustc_abi/src/layout.rs index 22187800922..944b1996ee1 100644 --- a/compiler/rustc_abi/src/layout.rs +++ b/compiler/rustc_abi/src/layout.rs @@ -350,7 +350,7 @@ impl LayoutCalculator { is_enum: bool, is_special_no_niche: bool, discr_range_of_repr: impl Fn(i128, i128) -> (Integer, bool), - discriminants: impl Iterator, + discriminants: impl Iterator, always_sized: bool, ) -> LayoutCalculatorResult { let (present_first, present_second) = { @@ -583,7 +583,7 @@ impl LayoutCalculator { repr: &ReprOptions, variants: &IndexSlice>, discr_range_of_repr: impl Fn(i128, i128) -> (Integer, bool), - discriminants: impl Iterator, + discriminants: impl Iterator, ) -> LayoutCalculatorResult { let dl = self.cx.data_layout(); // bail if the enum has an incoherent repr that cannot be computed @@ -767,9 +767,9 @@ impl LayoutCalculator { if discr_type.is_signed() { // sign extend the raw representation to be an i128 // FIXME: do this at the discriminant iterator creation sites - discr_int.size().sign_extend(val as u128) + discr_int.size().sign_extend(val) } else { - val + val as i128 } }) .collect(); diff --git a/compiler/rustc_ty_utils/src/layout.rs b/compiler/rustc_ty_utils/src/layout.rs index abec1850502..8a3c8bd7b3f 100644 --- a/compiler/rustc_ty_utils/src/layout.rs +++ b/compiler/rustc_ty_utils/src/layout.rs @@ -718,7 +718,7 @@ fn layout_of_uncached<'tcx>( let discriminants_iter = || { def.is_enum() - .then(|| def.discriminants(tcx).map(|(v, d)| (v, d.val as i128))) + .then(|| def.discriminants(tcx).map(|(v, d)| (v, d.val))) .into_flat_iter() };