@@ -723,19 +723,23 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
723
723
Ok ( op)
724
724
}
725
725
726
+ pub ( super ) fn adjust_const_scalar (
727
+ & self ,
728
+ scalar : Scalar ,
729
+ ) -> InterpResult < ' tcx , Scalar < M :: Provenance > > {
730
+ Ok ( match scalar {
731
+ Scalar :: Ptr ( ptr, size) => Scalar :: Ptr ( self . global_base_pointer ( ptr) ?, size) ,
732
+ Scalar :: Int ( int) => Scalar :: Int ( int) ,
733
+ } )
734
+ }
735
+
726
736
pub ( crate ) fn const_val_to_op (
727
737
& self ,
728
738
val_val : mir:: ConstValue < ' tcx > ,
729
739
ty : Ty < ' tcx > ,
730
740
layout : Option < TyAndLayout < ' tcx > > ,
731
741
) -> InterpResult < ' tcx , OpTy < ' tcx , M :: Provenance > > {
732
742
// Other cases need layout.
733
- let adjust_scalar = |scalar| -> InterpResult < ' tcx , _ > {
734
- Ok ( match scalar {
735
- Scalar :: Ptr ( ptr, size) => Scalar :: Ptr ( self . global_base_pointer ( ptr) ?, size) ,
736
- Scalar :: Int ( int) => Scalar :: Int ( int) ,
737
- } )
738
- } ;
739
743
let layout = from_known_layout ( self . tcx , self . param_env , layout, || self . layout_of ( ty) ) ?;
740
744
let imm = match val_val {
741
745
mir:: ConstValue :: Indirect { alloc_id, offset } => {
@@ -744,7 +748,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
744
748
let ptr = self . global_base_pointer ( Pointer :: new ( alloc_id, offset) ) ?;
745
749
return Ok ( self . ptr_to_mplace ( ptr. into ( ) , layout) . into ( ) ) ;
746
750
}
747
- mir:: ConstValue :: Scalar ( x) => adjust_scalar ( x) ?. into ( ) ,
751
+ mir:: ConstValue :: Scalar ( x) => self . adjust_const_scalar ( x) ?. into ( ) ,
748
752
mir:: ConstValue :: ZeroSized => Immediate :: Uninit ,
749
753
mir:: ConstValue :: Slice { data, meta } => {
750
754
// We rely on mutability being set correctly in `data` to prevent writes
0 commit comments