@@ -8,8 +8,9 @@ use rustc_hir::def::{DefKind, Res};
88use rustc_hir:: { BinOp , BinOpKind , Block , Expr , ExprKind , HirId , QPath , UnOp } ;
99use rustc_lint:: LateContext ;
1010use rustc_middle:: ty:: subst:: { Subst , SubstsRef } ;
11- use rustc_middle:: ty:: { self , Ty , TyCtxt } ;
11+ use rustc_middle:: ty:: { self , Ty , TyCtxt , ScalarInt } ;
1212use rustc_middle:: { bug, span_bug} ;
13+ use rustc_middle:: mir:: interpret:: Scalar ;
1314use rustc_span:: symbol:: Symbol ;
1415use std:: cmp:: Ordering :: { self , Equal } ;
1516use std:: convert:: TryInto ;
@@ -500,21 +501,21 @@ impl<'a, 'tcx> ConstEvalLateContext<'a, 'tcx> {
500501}
501502
502503pub fn miri_to_const ( result : & ty:: Const < ' _ > ) -> Option < Constant > {
503- use rustc_middle:: mir:: interpret:: { ConstValue , Scalar } ;
504+ use rustc_middle:: mir:: interpret:: { ConstValue } ;
504505 match result. val {
505- ty:: ConstKind :: Value ( ConstValue :: Scalar ( Scalar :: Raw { data : d , .. } ) ) => {
506+ ty:: ConstKind :: Value ( ConstValue :: Scalar ( Scalar :: Raw ( int ) ) ) => {
506507 match result. ty . kind ( ) {
507- ty:: Bool => Some ( Constant :: Bool ( d == 1 ) ) ,
508- ty:: Uint ( _) | ty:: Int ( _) => Some ( Constant :: Int ( d ) ) ,
508+ ty:: Bool => Some ( Constant :: Bool ( int == ScalarInt :: TRUE ) ) ,
509+ ty:: Uint ( _) | ty:: Int ( _) => Some ( Constant :: Int ( int . assert_bits ( int . size ( ) ) ) ) ,
509510 ty:: Float ( FloatTy :: F32 ) => Some ( Constant :: F32 ( f32:: from_bits (
510- d . try_into ( ) . expect ( "invalid f32 bit representation" ) ,
511+ int . try_into ( ) . expect ( "invalid f32 bit representation" ) ,
511512 ) ) ) ,
512513 ty:: Float ( FloatTy :: F64 ) => Some ( Constant :: F64 ( f64:: from_bits (
513- d . try_into ( ) . expect ( "invalid f64 bit representation" ) ,
514+ int . try_into ( ) . expect ( "invalid f64 bit representation" ) ,
514515 ) ) ) ,
515516 ty:: RawPtr ( type_and_mut) => {
516517 if let ty:: Uint ( _) = type_and_mut. ty . kind ( ) {
517- return Some ( Constant :: RawPtr ( d ) ) ;
518+ return Some ( Constant :: RawPtr ( int . assert_bits ( int . size ( ) ) ) ) ;
518519 }
519520 None
520521 } ,
0 commit comments