@@ -35,7 +35,7 @@ fn make_shim<'tcx>(tcx: TyCtxt<'tcx>, instance: ty::InstanceDef<'tcx>) -> &'tcx
35
35
ty:: InstanceDef :: VtableShim ( def_id) => {
36
36
build_call_shim (
37
37
tcx,
38
- def_id ,
38
+ instance ,
39
39
Adjustment :: DerefMove ,
40
40
CallKind :: Direct ( def_id) ,
41
41
None ,
@@ -60,7 +60,7 @@ fn make_shim<'tcx>(tcx: TyCtxt<'tcx>, instance: ty::InstanceDef<'tcx>) -> &'tcx
60
60
61
61
build_call_shim (
62
62
tcx,
63
- def_id ,
63
+ instance ,
64
64
adjustment,
65
65
CallKind :: Indirect ,
66
66
Some ( arg_tys)
@@ -74,13 +74,13 @@ fn make_shim<'tcx>(tcx: TyCtxt<'tcx>, instance: ty::InstanceDef<'tcx>) -> &'tcx
74
74
ty:: InstanceDef :: ReifyShim ( def_id) => {
75
75
build_call_shim (
76
76
tcx,
77
- def_id ,
77
+ instance ,
78
78
Adjustment :: Identity ,
79
79
CallKind :: Direct ( def_id) ,
80
80
None
81
81
)
82
82
}
83
- ty:: InstanceDef :: ClosureOnceShim { call_once } => {
83
+ ty:: InstanceDef :: ClosureOnceShim { call_once : _ } => {
84
84
let fn_mut = tcx. lang_items ( ) . fn_mut_trait ( ) . unwrap ( ) ;
85
85
let call_mut = tcx
86
86
. associated_items ( fn_mut)
@@ -89,7 +89,7 @@ fn make_shim<'tcx>(tcx: TyCtxt<'tcx>, instance: ty::InstanceDef<'tcx>) -> &'tcx
89
89
90
90
build_call_shim (
91
91
tcx,
92
- call_once ,
92
+ instance ,
93
93
Adjustment :: RefMut ,
94
94
CallKind :: Direct ( call_mut) ,
95
95
None
@@ -697,25 +697,38 @@ impl CloneShimBuilder<'tcx> {
697
697
}
698
698
}
699
699
700
- /// Builds a "call" shim for `def_id `. The shim calls the
700
+ /// Builds a "call" shim for `instance `. The shim calls the
701
701
/// function specified by `call_kind`, first adjusting its first
702
702
/// argument according to `rcvr_adjustment`.
703
703
///
704
704
/// If `untuple_args` is a vec of types, the second argument of the
705
705
/// function will be untupled as these types.
706
706
fn build_call_shim < ' tcx > (
707
707
tcx : TyCtxt < ' tcx > ,
708
- def_id : DefId ,
708
+ instance : ty :: InstanceDef < ' tcx > ,
709
709
rcvr_adjustment : Adjustment ,
710
710
call_kind : CallKind ,
711
711
untuple_args : Option < & [ Ty < ' tcx > ] > ,
712
712
) -> BodyCache < ' tcx > {
713
- debug ! ( "build_call_shim(def_id ={:?}, rcvr_adjustment={:?}, \
713
+ debug ! ( "build_call_shim(instance ={:?}, rcvr_adjustment={:?}, \
714
714
call_kind={:?}, untuple_args={:?})",
715
- def_id , rcvr_adjustment, call_kind, untuple_args) ;
715
+ instance , rcvr_adjustment, call_kind, untuple_args) ;
716
716
717
+ let def_id = instance. def_id ( ) ;
717
718
let sig = tcx. fn_sig ( def_id) ;
718
- let sig = tcx. erase_late_bound_regions ( & sig) ;
719
+ let mut sig = tcx. erase_late_bound_regions ( & sig) ;
720
+
721
+ // FIXME(eddyb) avoid having this snippet both here and in
722
+ // `Instance::fn_sig` (introduce `InstanceDef::fn_sig`?).
723
+ if let ty:: InstanceDef :: VtableShim ( ..) = instance {
724
+ // Modify fn(self, ...) to fn(self: *mut Self, ...)
725
+ let mut inputs_and_output = sig. inputs_and_output . to_vec ( ) ;
726
+ let self_arg = & mut inputs_and_output[ 0 ] ;
727
+ debug_assert ! ( tcx. generics_of( def_id) . has_self && * self_arg == tcx. types. self_param) ;
728
+ * self_arg = tcx. mk_mut_ptr ( * self_arg) ;
729
+ sig. inputs_and_output = tcx. intern_type_list ( & inputs_and_output) ;
730
+ }
731
+
719
732
let span = tcx. def_span ( def_id) ;
720
733
721
734
debug ! ( "build_call_shim: sig={:?}" , sig) ;
@@ -730,14 +743,7 @@ fn build_call_shim<'tcx>(
730
743
let rcvr = match rcvr_adjustment {
731
744
Adjustment :: Identity => Operand :: Move ( rcvr_l) ,
732
745
Adjustment :: Deref => Operand :: Copy ( tcx. mk_place_deref ( rcvr_l) ) ,
733
- Adjustment :: DerefMove => {
734
- // fn(Self, ...) -> fn(*mut Self, ...)
735
- let arg_ty = local_decls[ rcvr_arg] . ty ;
736
- debug_assert ! ( tcx. generics_of( def_id) . has_self && arg_ty == tcx. types. self_param) ;
737
- local_decls[ rcvr_arg] . ty = tcx. mk_mut_ptr ( arg_ty) ;
738
-
739
- Operand :: Move ( tcx. mk_place_deref ( rcvr_l) )
740
- }
746
+ Adjustment :: DerefMove => Operand :: Move ( tcx. mk_place_deref ( rcvr_l) ) ,
741
747
Adjustment :: RefMut => {
742
748
// let rcvr = &mut rcvr;
743
749
let ref_rcvr = local_decls. push ( temp_decl (
0 commit comments