about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorEduard-Mihai Burtescu <edy.burt@gmail.com>2019-10-28 21:16:41 +0200
committerEduard-Mihai Burtescu <edy.burt@gmail.com>2019-12-03 12:54:36 +0200
commit552ea447e48264036f7e67159358dec855e9c9ba (patch)
tree9d5c9284fc67b4638d8097339549266773b25b99 /src
parent4787e97475de6be9487e3d9255a9c2d3c0bf9252 (diff)
downloadrust-552ea447e48264036f7e67159358dec855e9c9ba.tar.gz
rust-552ea447e48264036f7e67159358dec855e9c9ba.zip
rustc: combine Instance::fn_sig_noadjust and Instance::fn_sig.
Diffstat (limited to 'src')
-rw-r--r--src/librustc/ty/instance.rs32
1 files changed, 15 insertions, 17 deletions
diff --git a/src/librustc/ty/instance.rs b/src/librustc/ty/instance.rs
index 777db38850f..856be6f3c77 100644
--- a/src/librustc/ty/instance.rs
+++ b/src/librustc/ty/instance.rs
@@ -62,12 +62,24 @@ impl<'tcx> Instance<'tcx> {
         )
     }
 
-    fn fn_sig_noadjust(&self, tcx: TyCtxt<'tcx>) -> PolyFnSig<'tcx> {
+    pub fn fn_sig(&self, tcx: TyCtxt<'tcx>) -> PolyFnSig<'tcx> {
         let ty = self.ty(tcx);
         match ty.kind {
             ty::FnDef(..) |
             // Shims currently have type FnPtr. Not sure this should remain.
-            ty::FnPtr(_) => ty.fn_sig(tcx),
+            ty::FnPtr(_) => {
+                let mut sig = ty.fn_sig(tcx);
+                if let InstanceDef::VtableShim(..) = self.def {
+                    // Modify `fn(self, ...)` to `fn(self: *mut Self, ...)`.
+                    sig = sig.map_bound(|mut sig| {
+                        let mut inputs_and_output = sig.inputs_and_output.to_vec();
+                        inputs_and_output[0] = tcx.mk_mut_ptr(inputs_and_output[0]);
+                        sig.inputs_and_output = tcx.intern_type_list(&inputs_and_output);
+                        sig
+                    });
+                }
+                sig
+            }
             ty::Closure(def_id, substs) => {
                 let sig = substs.as_closure().sig(def_id, tcx);
 
@@ -108,22 +120,8 @@ impl<'tcx> Instance<'tcx> {
                     )
                 })
             }
-            _ => bug!("unexpected type {:?} in Instance::fn_sig_noadjust", ty)
-        }
-    }
-
-    pub fn fn_sig(&self, tcx: TyCtxt<'tcx>) -> ty::PolyFnSig<'tcx> {
-        let mut fn_sig = self.fn_sig_noadjust(tcx);
-        if let InstanceDef::VtableShim(..) = self.def {
-            // Modify `fn(self, ...)` to `fn(self: *mut Self, ...)`.
-            fn_sig = fn_sig.map_bound(|mut fn_sig| {
-                let mut inputs_and_output = fn_sig.inputs_and_output.to_vec();
-                inputs_and_output[0] = tcx.mk_mut_ptr(inputs_and_output[0]);
-                fn_sig.inputs_and_output = tcx.intern_type_list(&inputs_and_output);
-                fn_sig
-            });
+            _ => bug!("unexpected type {:?} in Instance::fn_sig", ty)
         }
-        fn_sig
     }
 }