@@ -180,6 +180,13 @@ impl<'tcx, Tag: Copy> From<MPlaceTy<'tcx, Tag>> for OpTy<'tcx, Tag> {
180180 }
181181}
182182
183+ impl < ' tcx , Tag : Copy > From < & ' _ MPlaceTy < ' tcx , Tag > > for OpTy < ' tcx , Tag > {
184+ #[ inline( always) ]
185+ fn from ( mplace : & MPlaceTy < ' tcx , Tag > ) -> Self {
186+ OpTy { op : Operand :: Indirect ( * * mplace) , layout : mplace. layout }
187+ }
188+ }
189+
183190impl < ' tcx , Tag > From < ImmTy < ' tcx , Tag > > for OpTy < ' tcx , Tag > {
184191 #[ inline( always) ]
185192 fn from ( val : ImmTy < ' tcx , Tag > ) -> Self {
@@ -243,7 +250,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
243250 /// Returns `None` if the layout does not permit loading this as a value.
244251 fn try_read_immediate_from_mplace (
245252 & self ,
246- mplace : MPlaceTy < ' tcx , M :: PointerTag > ,
253+ mplace : & MPlaceTy < ' tcx , M :: PointerTag > ,
247254 ) -> InterpResult < ' tcx , Option < ImmTy < ' tcx , M :: PointerTag > > > {
248255 if mplace. layout . is_unsized ( ) {
249256 // Don't touch unsized
@@ -307,11 +314,11 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
307314 src : & OpTy < ' tcx , M :: PointerTag > ,
308315 ) -> InterpResult < ' tcx , Result < ImmTy < ' tcx , M :: PointerTag > , MPlaceTy < ' tcx , M :: PointerTag > > > {
309316 Ok ( match src. try_as_mplace ( self ) {
310- Ok ( mplace) => {
317+ Ok ( ref mplace) => {
311318 if let Some ( val) = self . try_read_immediate_from_mplace ( mplace) ? {
312319 Ok ( val)
313320 } else {
314- Err ( mplace)
321+ Err ( * mplace)
315322 }
316323 }
317324 Err ( val) => Ok ( val) ,
@@ -340,7 +347,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
340347 }
341348
342349 // Turn the wide MPlace into a string (must already be dereferenced!)
343- pub fn read_str ( & self , mplace : MPlaceTy < ' tcx , M :: PointerTag > ) -> InterpResult < ' tcx , & str > {
350+ pub fn read_str ( & self , mplace : & MPlaceTy < ' tcx , M :: PointerTag > ) -> InterpResult < ' tcx , & str > {
344351 let len = mplace. len ( self ) ?;
345352 let bytes = self . memory . read_bytes ( mplace. ptr , Size :: from_bytes ( len) ) ?;
346353 let str = std:: str:: from_utf8 ( bytes) . map_err ( |err| err_ub ! ( InvalidStr ( err) ) ) ?;
@@ -354,7 +361,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
354361 field : usize ,
355362 ) -> InterpResult < ' tcx , OpTy < ' tcx , M :: PointerTag > > {
356363 let base = match op. try_as_mplace ( self ) {
357- Ok ( mplace) => {
364+ Ok ( ref mplace) => {
358365 // We can reuse the mplace field computation logic for indirect operands.
359366 let field = self . mplace_field ( mplace, field) ?;
360367 return Ok ( field. into ( ) ) ;
@@ -397,7 +404,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
397404 } else {
398405 // Indexing into a big array. This must be an mplace.
399406 let mplace = op. assert_mem_place ( self ) ;
400- Ok ( self . mplace_index ( mplace, index) ?. into ( ) )
407+ Ok ( self . mplace_index ( & mplace, index) ?. into ( ) )
401408 }
402409 }
403410
@@ -408,7 +415,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
408415 ) -> InterpResult < ' tcx , OpTy < ' tcx , M :: PointerTag > > {
409416 // Downcasts only change the layout
410417 Ok ( match op. try_as_mplace ( self ) {
411- Ok ( mplace) => self . mplace_downcast ( mplace, variant) ?. into ( ) ,
418+ Ok ( ref mplace) => self . mplace_downcast ( mplace, variant) ?. into ( ) ,
412419 Err ( ..) => {
413420 let layout = op. layout . for_variant ( self , variant) ;
414421 OpTy { layout, ..* op }
@@ -430,7 +437,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
430437 // The rest should only occur as mplace, we do not use Immediates for types
431438 // allowing such operations. This matches place_projection forcing an allocation.
432439 let mplace = base. assert_mem_place ( self ) ;
433- self . mplace_projection ( mplace, proj_elem) ?. into ( )
440+ self . mplace_projection ( & mplace, proj_elem) ?. into ( )
434441 }
435442 } )
436443 }
0 commit comments