mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-27 18:57:42 +03:00
Reuse sign_extend helper
This commit is contained in:
@@ -769,7 +769,6 @@ struct TmpLayout<FieldIdx: Idx, VariantIdx: Idx> {
|
||||
|
||||
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 @@ struct TmpLayout<FieldIdx: Idx, VariantIdx: Idx> {
|
||||
.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
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
|
||||
#[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>,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user