Skip to content

Commit 219bad4

Browse files
committed
Reuse sign_extend helper
1 parent 75bdbf2 commit 219bad4

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

compiler/rustc_abi/src/layout.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -769,7 +769,6 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
769769

770770
let discr_type = repr.discr_type();
771771
let discr_int = Integer::from_attr(dl, discr_type);
772-
let bits = discr_int.size().bits();
773772
// Because we can only represent one range of valid values, we'll look for the
774773
// largest range of invalid values and pick everything else as the range of valid
775774
// values.
@@ -780,7 +779,8 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
780779
.map(|(_, val)| {
781780
if discr_type.is_signed() {
782781
// sign extend the raw representation to be an i128
783-
(val << (128 - bits)) >> (128 - bits)
782+
// FIXME: do this at the discriminant iterator creation sites
783+
discr_int.size().sign_extend(val as u128)
784784
} else {
785785
val
786786
}

compiler/rustc_middle/src/ty/util.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ use crate::ty::{
3232

3333
#[derive(Copy, Clone, Debug)]
3434
pub struct Discr<'tcx> {
35-
/// Bit representation of the discriminant (e.g., `-128i8` is `0xFF_u128`).
35+
/// Bit representation of the discriminant (e.g., `-1i8` is `0xFF_u128`).
3636
pub val: u128,
3737
pub ty: Ty<'tcx>,
3838
}

0 commit comments

Comments
 (0)