@@ -180,6 +180,13 @@ impl<'tcx, Tag: Copy> From<MPlaceTy<'tcx, Tag>> for OpTy<'tcx, Tag> {
180
180
}
181
181
}
182
182
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
+
183
190
impl < ' tcx , Tag > From < ImmTy < ' tcx , Tag > > for OpTy < ' tcx , Tag > {
184
191
#[ inline( always) ]
185
192
fn from ( val : ImmTy < ' tcx , Tag > ) -> Self {
@@ -243,7 +250,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
243
250
/// Returns `None` if the layout does not permit loading this as a value.
244
251
fn try_read_immediate_from_mplace (
245
252
& self ,
246
- mplace : MPlaceTy < ' tcx , M :: PointerTag > ,
253
+ mplace : & MPlaceTy < ' tcx , M :: PointerTag > ,
247
254
) -> InterpResult < ' tcx , Option < ImmTy < ' tcx , M :: PointerTag > > > {
248
255
if mplace. layout . is_unsized ( ) {
249
256
// Don't touch unsized
@@ -307,11 +314,11 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
307
314
src : & OpTy < ' tcx , M :: PointerTag > ,
308
315
) -> InterpResult < ' tcx , Result < ImmTy < ' tcx , M :: PointerTag > , MPlaceTy < ' tcx , M :: PointerTag > > > {
309
316
Ok ( match src. try_as_mplace ( self ) {
310
- Ok ( mplace) => {
317
+ Ok ( ref mplace) => {
311
318
if let Some ( val) = self . try_read_immediate_from_mplace ( mplace) ? {
312
319
Ok ( val)
313
320
} else {
314
- Err ( mplace)
321
+ Err ( * mplace)
315
322
}
316
323
}
317
324
Err ( val) => Ok ( val) ,
@@ -340,7 +347,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
340
347
}
341
348
342
349
// 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 > {
344
351
let len = mplace. len ( self ) ?;
345
352
let bytes = self . memory . read_bytes ( mplace. ptr , Size :: from_bytes ( len) ) ?;
346
353
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> {
354
361
field : usize ,
355
362
) -> InterpResult < ' tcx , OpTy < ' tcx , M :: PointerTag > > {
356
363
let base = match op. try_as_mplace ( self ) {
357
- Ok ( mplace) => {
364
+ Ok ( ref mplace) => {
358
365
// We can reuse the mplace field computation logic for indirect operands.
359
366
let field = self . mplace_field ( mplace, field) ?;
360
367
return Ok ( field. into ( ) ) ;
@@ -397,7 +404,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
397
404
} else {
398
405
// Indexing into a big array. This must be an mplace.
399
406
let mplace = op. assert_mem_place ( self ) ;
400
- Ok ( self . mplace_index ( mplace, index) ?. into ( ) )
407
+ Ok ( self . mplace_index ( & mplace, index) ?. into ( ) )
401
408
}
402
409
}
403
410
@@ -408,7 +415,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
408
415
) -> InterpResult < ' tcx , OpTy < ' tcx , M :: PointerTag > > {
409
416
// Downcasts only change the layout
410
417
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 ( ) ,
412
419
Err ( ..) => {
413
420
let layout = op. layout . for_variant ( self , variant) ;
414
421
OpTy { layout, ..* op }
@@ -430,7 +437,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
430
437
// The rest should only occur as mplace, we do not use Immediates for types
431
438
// allowing such operations. This matches place_projection forcing an allocation.
432
439
let mplace = base. assert_mem_place ( self ) ;
433
- self . mplace_projection ( mplace, proj_elem) ?. into ( )
440
+ self . mplace_projection ( & mplace, proj_elem) ?. into ( )
434
441
}
435
442
} )
436
443
}
0 commit comments