Skip to content

Commit 937ca43

Browse files
authored
Rollup merge of #70189 - RalfJung:is_signed, r=eddyb
Abi::is_signed: assert that we are a Scalar A bit more sanity checking, suggested by @eddyb. This makes this method actually "safer" than `TyS::is_signed`, so I made sure Miri consistently uses the `Abi` version. Though I am not sure if this would have caught the mistake where the layout of a zero-sized enum was asked for its sign. r? @eddyb
2 parents 832daf7 + 5930da4 commit 937ca43

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

src/librustc_mir/interpret/operand.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
604604
.not_undef()
605605
.and_then(|raw_discr| self.force_bits(raw_discr, discr_val.layout.size))
606606
.map_err(|_| err_ub!(InvalidDiscriminant(raw_discr.erase_tag())))?;
607-
let real_discr = if discr_val.layout.ty.is_signed() {
607+
let real_discr = if discr_val.layout.abi.is_signed() {
608608
// going from layout tag type to typeck discriminant type
609609
// requires first sign extending with the discriminant layout
610610
let sexted = sign_extend(bits_discr, discr_val.layout.size) as i128;

src/librustc_target/abi/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -751,7 +751,7 @@ impl Abi {
751751
Primitive::Int(_, signed) => signed,
752752
_ => false,
753753
},
754-
_ => false,
754+
_ => panic!("`is_signed` on non-scalar ABI {:?}", self),
755755
}
756756
}
757757

0 commit comments

Comments
 (0)