]> git.lizzy.rs Git - rust.git/commitdiff
Fix print_miri_value for signed integers
authorvarkor <github@varkor.com>
Thu, 24 May 2018 11:13:28 +0000 (12:13 +0100)
committervarkor <github@varkor.com>
Thu, 16 Aug 2018 19:09:05 +0000 (20:09 +0100)
src/librustc/mir/mod.rs
src/librustc_mir/hair/pattern/_match.rs

index 8ceff303774b596a265af6a1dfac05a09589914c..2013766aa39ceafc472f2a46432dbffb203fbbf0 100644 (file)
@@ -35,6 +35,7 @@
 use std::vec::IntoIter;
 use std::{iter, mem, option, u32};
 use syntax::ast::{self, Name};
+use syntax::attr::SignedInt;
 use syntax::symbol::InternedString;
 use syntax_pos::{Span, DUMMY_SP};
 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
     }
 }
 
-pub fn print_miri_value<W: Write>(value: Value, ty: Ty, f: &mut W) -> fmt::Result {
+pub fn print_miri_value<'tcx, W: Write>(value: Value, ty: Ty<'tcx>, f: &mut W) -> fmt::Result {
     use ty::TypeVariants::*;
     // print some primitives
     if let Value::Scalar(ScalarMaybeUndef::Scalar(Scalar::Bits { bits, .. })) = value {
index 86f0e95a9032a67a2b9901abcdc38e521a2a4b44..c666469f3574d5e3a368cb71e42147565fa6bb8e 100644 (file)
@@ -668,19 +668,14 @@ fn convert(tcx: TyCtxt<'_, 'tcx, 'tcx>,
             ty::TyInt(_) => {
                 // FIXME(49937): refactor these bit manipulations into interpret.
                 let bits = tcx.layout_of(ty::ParamEnv::reveal_all().and(ty))
-                                 .unwrap().size.bits() as u128;
+                              .unwrap().size.bits() as u128;
                 let min = 1u128 << (bits - 1);
                 let mask = !0u128 >> (128 - bits);
                 if encode {
                     let offset = |x: u128| x.wrapping_sub(min) & mask;
                     (offset(lo), offset(hi))
                 } else {
-                    let offset = |x: u128| {
-                        // FIXME: this shouldn't be necessary once `print_miri_value`
-                        // sign-extends `TyInt`.
-                        interpret::sign_extend(tcx, x.wrapping_add(min) & mask, ty)
-                                  .expect("layout error for TyInt")
-                    };
+                    let offset = |x: u128| x.wrapping_add(min) & mask;
                     (offset(lo), offset(hi))
                 }
             }