@@ -723,19 +723,23 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
723723 Ok ( op)
724724 }
725725
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+
726736 pub ( crate ) fn const_val_to_op (
727737 & self ,
728738 val_val : mir:: ConstValue < ' tcx > ,
729739 ty : Ty < ' tcx > ,
730740 layout : Option < TyAndLayout < ' tcx > > ,
731741 ) -> InterpResult < ' tcx , OpTy < ' tcx , M :: Provenance > > {
732742 // 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- } ;
739743 let layout = from_known_layout ( self . tcx , self . param_env , layout, || self . layout_of ( ty) ) ?;
740744 let imm = match val_val {
741745 mir:: ConstValue :: Indirect { alloc_id, offset } => {
@@ -744,7 +748,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
744748 let ptr = self . global_base_pointer ( Pointer :: new ( alloc_id, offset) ) ?;
745749 return Ok ( self . ptr_to_mplace ( ptr. into ( ) , layout) . into ( ) ) ;
746750 }
747- mir:: ConstValue :: Scalar ( x) => adjust_scalar ( x) ?. into ( ) ,
751+ mir:: ConstValue :: Scalar ( x) => self . adjust_const_scalar ( x) ?. into ( ) ,
748752 mir:: ConstValue :: ZeroSized => Immediate :: Uninit ,
749753 mir:: ConstValue :: Slice { data, meta } => {
750754 // We rely on mutability being set correctly in `data` to prevent writes
0 commit comments