Skip to content

Commit be12b24

Browse files
committed
Fix print_miri_value for signed integers
1 parent 97a032e commit be12b24

File tree

2 files changed

+4
-8
lines changed

2 files changed

+4
-8
lines changed

src/librustc/mir/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ use std::slice;
3535
use std::vec::IntoIter;
3636
use std::{iter, mem, option, u32};
3737
use syntax::ast::{self, Name};
38+
use syntax::attr::SignedInt;
3839
use syntax::symbol::InternedString;
3940
use syntax_pos::{Span, DUMMY_SP};
4041
use ty::fold::{TypeFoldable, TypeFolder, TypeVisitor};
@@ -2228,7 +2229,7 @@ pub fn fmt_const_val<W: Write>(fmt: &mut W, const_val: &ty::Const) -> fmt::Resul
22282229
}
22292230
}
22302231

2231-
pub fn print_miri_value<W: Write>(value: Value, ty: Ty, f: &mut W) -> fmt::Result {
2232+
pub fn print_miri_value<'tcx, W: Write>(value: Value, ty: Ty<'tcx>, f: &mut W) -> fmt::Result {
22322233
use ty::TypeVariants::*;
22332234
// print some primitives
22342235
if let Value::Scalar(ScalarMaybeUndef::Scalar(Scalar::Bits { bits, .. })) = value {

src/librustc_mir/hair/pattern/_match.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -668,19 +668,14 @@ impl<'tcx> IntRange<'tcx> {
668668
ty::TyInt(_) => {
669669
// FIXME(49937): refactor these bit manipulations into interpret.
670670
let bits = tcx.layout_of(ty::ParamEnv::reveal_all().and(ty))
671-
.unwrap().size.bits() as u128;
671+
.unwrap().size.bits() as u128;
672672
let min = 1u128 << (bits - 1);
673673
let mask = !0u128 >> (128 - bits);
674674
if encode {
675675
let offset = |x: u128| x.wrapping_sub(min) & mask;
676676
(offset(lo), offset(hi))
677677
} else {
678-
let offset = |x: u128| {
679-
// FIXME: this shouldn't be necessary once `print_miri_value`
680-
// sign-extends `TyInt`.
681-
interpret::sign_extend(tcx, x.wrapping_add(min) & mask, ty)
682-
.expect("layout error for TyInt")
683-
};
678+
let offset = |x: u128| x.wrapping_add(min) & mask;
684679
(offset(lo), offset(hi))
685680
}
686681
}

0 commit comments

Comments
 (0)