@@ -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
@@ -689,25 +689,38 @@ impl CloneShimBuilder<'tcx> {
689
689
}
690
690
}
691
691
692
- /// Builds a "call" shim for `def_id `. The shim calls the
692
+ /// Builds a "call" shim for `instance `. The shim calls the
693
693
/// function specified by `call_kind`, first adjusting its first
694
694
/// argument according to `rcvr_adjustment`.
695
695
///
696
696
/// If `untuple_args` is a vec of types, the second argument of the
697
697
/// function will be untupled as these types.
698
698
fn build_call_shim < ' tcx > (
699
699
tcx : TyCtxt < ' tcx > ,
700
- def_id : DefId ,
700
+ instance : ty :: InstanceDef < ' tcx > ,
701
701
rcvr_adjustment : Adjustment ,
702
702
call_kind : CallKind ,
703
703
untuple_args : Option < & [ Ty < ' tcx > ] > ,
704
704
) -> Body < ' tcx > {
705
- debug ! ( "build_call_shim(def_id ={:?}, rcvr_adjustment={:?}, \
705
+ debug ! ( "build_call_shim(instance ={:?}, rcvr_adjustment={:?}, \
706
706
call_kind={:?}, untuple_args={:?})",
707
- def_id , rcvr_adjustment, call_kind, untuple_args) ;
707
+ instance , rcvr_adjustment, call_kind, untuple_args) ;
708
708
709
+ let def_id = instance. def_id ( ) ;
709
710
let sig = tcx. fn_sig ( def_id) ;
710
- let sig = tcx. erase_late_bound_regions ( & sig) ;
711
+ let mut sig = tcx. erase_late_bound_regions ( & sig) ;
712
+
713
+ // FIXME(eddyb) avoid having this snippet both here and in
714
+ // `Instance::fn_sig` (introduce `InstanceDef::fn_sig`?).
715
+ if let ty:: InstanceDef :: VtableShim ( ..) = instance {
716
+ // Modify fn(self, ...) to fn(self: *mut Self, ...)
717
+ let mut inputs_and_output = sig. inputs_and_output . to_vec ( ) ;
718
+ let self_arg = & mut inputs_and_output[ 0 ] ;
719
+ debug_assert ! ( tcx. generics_of( def_id) . has_self && * self_arg == tcx. types. self_param) ;
720
+ * self_arg = tcx. mk_mut_ptr ( * self_arg) ;
721
+ sig. inputs_and_output = tcx. intern_type_list ( & inputs_and_output) ;
722
+ }
723
+
711
724
let span = tcx. def_span ( def_id) ;
712
725
713
726
debug ! ( "build_call_shim: sig={:?}" , sig) ;
@@ -722,14 +735,7 @@ fn build_call_shim<'tcx>(
722
735
let rcvr = match rcvr_adjustment {
723
736
Adjustment :: Identity => Operand :: Move ( rcvr_l) ,
724
737
Adjustment :: Deref => Operand :: Copy ( tcx. mk_place_deref ( rcvr_l) ) ,
725
- Adjustment :: DerefMove => {
726
- // fn(Self, ...) -> fn(*mut Self, ...)
727
- let arg_ty = local_decls[ rcvr_arg] . ty ;
728
- debug_assert ! ( tcx. generics_of( def_id) . has_self && arg_ty == tcx. types. self_param) ;
729
- local_decls[ rcvr_arg] . ty = tcx. mk_mut_ptr ( arg_ty) ;
730
-
731
- Operand :: Move ( tcx. mk_place_deref ( rcvr_l) )
732
- }
738
+ Adjustment :: DerefMove => Operand :: Move ( tcx. mk_place_deref ( rcvr_l) ) ,
733
739
Adjustment :: RefMut => {
734
740
// let rcvr = &mut rcvr;
735
741
let ref_rcvr = local_decls. push ( temp_decl (
0 commit comments