From 219bad49461f5c9fc318732a73a05af5d198fed2 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Tue, 29 Jul 2025 08:43:10 +0000 Subject: [PATCH] Reuse `sign_extend` helper --- compiler/rustc_abi/src/layout.rs | 4 ++-- compiler/rustc_middle/src/ty/util.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/compiler/rustc_abi/src/layout.rs b/compiler/rustc_abi/src/layout.rs index 90c63bc9db3c..c2405553756b 100644 --- a/compiler/rustc_abi/src/layout.rs +++ b/compiler/rustc_abi/src/layout.rs @@ -769,7 +769,6 @@ impl LayoutCalculator { let discr_type = repr.discr_type(); let discr_int = Integer::from_attr(dl, discr_type); - let bits = discr_int.size().bits(); // Because we can only represent one range of valid values, we'll look for the // largest range of invalid values and pick everything else as the range of valid // values. @@ -780,7 +779,8 @@ impl LayoutCalculator { .map(|(_, val)| { if discr_type.is_signed() { // sign extend the raw representation to be an i128 - (val << (128 - bits)) >> (128 - bits) + // FIXME: do this at the discriminant iterator creation sites + discr_int.size().sign_extend(val as u128) } else { val } diff --git a/compiler/rustc_middle/src/ty/util.rs b/compiler/rustc_middle/src/ty/util.rs index 174892c6f4d2..a7d07adf78f0 100644 --- a/compiler/rustc_middle/src/ty/util.rs +++ b/compiler/rustc_middle/src/ty/util.rs @@ -32,7 +32,7 @@ use crate::ty::{ #[derive(Copy, Clone, Debug)] pub struct Discr<'tcx> { - /// Bit representation of the discriminant (e.g., `-128i8` is `0xFF_u128`). + /// Bit representation of the discriminant (e.g., `-1i8` is `0xFF_u128`). pub val: u128, pub ty: Ty<'tcx>, }