@@ -40,13 +40,13 @@ impl<'tcx, Prov: Provenance> FnArg<'tcx, Prov> {
40
40
impl < ' mir , ' tcx : ' mir , M : Machine < ' mir , ' tcx > > InterpCx < ' mir , ' tcx , M > {
41
41
/// Make a copy of the given fn_arg. Any `InPlace` are degenerated to copies, no protection of the
42
42
/// original memory occurs.
43
- pub fn copy_fn_arg (
43
+ pub fn copy_fn_arg < ' a > (
44
44
& self ,
45
- arg : & FnArg < ' tcx , M :: Provenance > ,
46
- ) -> InterpResult < ' tcx , OpTy < ' tcx , M :: Provenance > > {
45
+ arg : & ' a FnArg < ' tcx , M :: Provenance > ,
46
+ ) -> InterpResult < ' tcx , Cow < ' a , OpTy < ' tcx , M :: Provenance > > > {
47
47
match arg {
48
- FnArg :: Copy ( op) => Ok ( op . clone ( ) ) ,
49
- FnArg :: InPlace ( place) => self . place_to_op ( & place) ,
48
+ FnArg :: Copy ( op) => Ok ( Cow :: Borrowed ( op ) ) ,
49
+ FnArg :: InPlace ( place) => Ok ( Cow :: Owned ( self . place_to_op ( & place) ? ) ) ,
50
50
}
51
51
}
52
52
@@ -56,7 +56,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
56
56
& self ,
57
57
args : & [ FnArg < ' tcx , M :: Provenance > ] ,
58
58
) -> InterpResult < ' tcx , Vec < OpTy < ' tcx , M :: Provenance > > > {
59
- args. iter ( ) . map ( |fn_arg| self . copy_fn_arg ( fn_arg) ) . collect ( )
59
+ args. iter ( ) . map ( |fn_arg| self . copy_fn_arg ( fn_arg) . map ( |x| x . into_owned ( ) ) ) . collect ( )
60
60
}
61
61
62
62
pub fn fn_arg_field (
@@ -637,7 +637,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
637
637
// An `InPlace` does nothing here, we keep the original receiver intact. We can't
638
638
// really pass the argument in-place anyway, and we are constructing a new
639
639
// `Immediate` receiver.
640
- let mut receiver = self . copy_fn_arg ( & args[ 0 ] ) ?;
640
+ let mut receiver = self . copy_fn_arg ( & args[ 0 ] ) ?. into_owned ( ) ;
641
641
let receiver_place = loop {
642
642
match receiver. layout . ty . kind ( ) {
643
643
ty:: Ref ( ..) | ty:: RawPtr ( ..) => {
0 commit comments