@@ -7,8 +7,9 @@ use rustc_data_structures::sync::Lrc;
7
7
use rustc_hir:: def:: { DefKind , Res } ;
8
8
use rustc_hir:: { BinOp , BinOpKind , Block , Expr , ExprKind , HirId , QPath , UnOp } ;
9
9
use rustc_lint:: LateContext ;
10
+ use rustc_middle:: mir:: interpret:: Scalar ;
10
11
use rustc_middle:: ty:: subst:: { Subst , SubstsRef } ;
11
- use rustc_middle:: ty:: { self , Ty , TyCtxt } ;
12
+ use rustc_middle:: ty:: { self , ScalarInt , Ty , TyCtxt } ;
12
13
use rustc_middle:: { bug, span_bug} ;
13
14
use rustc_span:: symbol:: Symbol ;
14
15
use std:: cmp:: Ordering :: { self , Equal } ;
@@ -500,21 +501,21 @@ impl<'a, 'tcx> ConstEvalLateContext<'a, 'tcx> {
500
501
}
501
502
502
503
pub fn miri_to_const ( result : & ty:: Const < ' _ > ) -> Option < Constant > {
503
- use rustc_middle:: mir:: interpret:: { ConstValue , Scalar } ;
504
+ use rustc_middle:: mir:: interpret:: ConstValue ;
504
505
match result. val {
505
- ty:: ConstKind :: Value ( ConstValue :: Scalar ( Scalar :: Raw { data : d , .. } ) ) => {
506
+ ty:: ConstKind :: Value ( ConstValue :: Scalar ( Scalar :: Int ( int ) ) ) => {
506
507
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 ( ) ) ) ) ,
509
510
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" ) ,
511
512
) ) ) ,
512
513
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" ) ,
514
515
) ) ) ,
515
516
ty:: RawPtr ( type_and_mut) => {
516
517
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 ( ) ) ) ) ;
518
519
}
519
520
None
520
521
} ,
0 commit comments