about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMasaki Hara <ackie.h.gmai@gmail.com>2018-09-10 23:00:50 +0900
committerMasaki Hara <ackie.h.gmai@gmail.com>2018-10-24 21:59:06 +0900
commit6fd914a1afc3d0d0f86e8a9a1bfacd55be053d58 (patch)
treedc61463dfb312ca6997deda587e04a883b01be3c
parent0ad4c6f85022642ddbb3fc10f1743eb4e16abef0 (diff)
downloadrust-6fd914a1afc3d0d0f86e8a9a1bfacd55be053d58.tar.gz
rust-6fd914a1afc3d0d0f86e8a9a1bfacd55be053d58.zip
Add vtable-shim helper methods for Instance.
-rw-r--r--src/librustc/ty/instance.rs27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/librustc/ty/instance.rs b/src/librustc/ty/instance.rs
index 9410bea2182..83029df0fe7 100644
--- a/src/librustc/ty/instance.rs
+++ b/src/librustc/ty/instance.rs
@@ -237,6 +237,25 @@ impl<'a, 'b, 'tcx> Instance<'tcx> {
         result
     }
 
+    pub fn resolve_for_vtable(tcx: TyCtxt<'a, 'tcx, 'tcx>,
+                              param_env: ty::ParamEnv<'tcx>,
+                              def_id: DefId,
+                              substs: &'tcx Substs<'tcx>) -> Option<Instance<'tcx>> {
+        debug!("resolve(def_id={:?}, substs={:?})", def_id, substs);
+        let fn_sig = tcx.fn_sig(def_id);
+        let is_vtable_shim =
+            fn_sig.inputs().skip_binder().len() > 0 && fn_sig.input(0).skip_binder().is_self();
+        if is_vtable_shim {
+            debug!(" => associated item with unsizeable self: Self");
+            Some(Instance {
+                def: InstanceDef::VtableShim(def_id),
+                substs,
+            })
+        } else {
+            Instance::resolve(tcx, param_env, def_id, substs)
+        }
+    }
+
     pub fn resolve_closure(
         tcx: TyCtxt<'a, 'tcx, 'tcx>,
         def_id: DefId,
@@ -251,6 +270,14 @@ impl<'a, 'b, 'tcx> Instance<'tcx> {
             _ => Instance::new(def_id, substs.substs)
         }
     }
+
+    pub fn is_vtable_shim(&self) -> bool {
+        if let InstanceDef::VtableShim(..) = self.def {
+            true
+        } else {
+            false
+        }
+    }
 }
 
 fn resolve_associated_item<'a, 'tcx>(