Skip to content

Commit 552ea44

Browse files
committed
rustc: combine Instance::fn_sig_noadjust and Instance::fn_sig.
1 parent 4787e97 commit 552ea44

File tree

1 file changed

+15
-17
lines changed

1 file changed

+15
-17
lines changed

src/librustc/ty/instance.rs

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,24 @@ impl<'tcx> Instance<'tcx> {
6262
)
6363
}
6464

65-
fn fn_sig_noadjust(&self, tcx: TyCtxt<'tcx>) -> PolyFnSig<'tcx> {
65+
pub fn fn_sig(&self, tcx: TyCtxt<'tcx>) -> PolyFnSig<'tcx> {
6666
let ty = self.ty(tcx);
6767
match ty.kind {
6868
ty::FnDef(..) |
6969
// Shims currently have type FnPtr. Not sure this should remain.
70-
ty::FnPtr(_) => ty.fn_sig(tcx),
70+
ty::FnPtr(_) => {
71+
let mut sig = ty.fn_sig(tcx);
72+
if let InstanceDef::VtableShim(..) = self.def {
73+
// Modify `fn(self, ...)` to `fn(self: *mut Self, ...)`.
74+
sig = sig.map_bound(|mut sig| {
75+
let mut inputs_and_output = sig.inputs_and_output.to_vec();
76+
inputs_and_output[0] = tcx.mk_mut_ptr(inputs_and_output[0]);
77+
sig.inputs_and_output = tcx.intern_type_list(&inputs_and_output);
78+
sig
79+
});
80+
}
81+
sig
82+
}
7183
ty::Closure(def_id, substs) => {
7284
let sig = substs.as_closure().sig(def_id, tcx);
7385

@@ -108,22 +120,8 @@ impl<'tcx> Instance<'tcx> {
108120
)
109121
})
110122
}
111-
_ => bug!("unexpected type {:?} in Instance::fn_sig_noadjust", ty)
112-
}
113-
}
114-
115-
pub fn fn_sig(&self, tcx: TyCtxt<'tcx>) -> ty::PolyFnSig<'tcx> {
116-
let mut fn_sig = self.fn_sig_noadjust(tcx);
117-
if let InstanceDef::VtableShim(..) = self.def {
118-
// Modify `fn(self, ...)` to `fn(self: *mut Self, ...)`.
119-
fn_sig = fn_sig.map_bound(|mut fn_sig| {
120-
let mut inputs_and_output = fn_sig.inputs_and_output.to_vec();
121-
inputs_and_output[0] = tcx.mk_mut_ptr(inputs_and_output[0]);
122-
fn_sig.inputs_and_output = tcx.intern_type_list(&inputs_and_output);
123-
fn_sig
124-
});
123+
_ => bug!("unexpected type {:?} in Instance::fn_sig", ty)
125124
}
126-
fn_sig
127125
}
128126
}
129127

0 commit comments

Comments
 (0)