+#[derive(Debug)]
+pub struct ImplMethod<'tcx> {
+ pub method: Rc<ty::Method<'tcx>>,
+ pub substs: &'tcx Substs<'tcx>,
+ pub is_provided: bool,
+}
+
+/// Locates the applicable definition of a method, given its name.
+pub fn get_impl_method<'tcx>(
+ tcx: &TyCtxt<'tcx>,
+ impl_def_id: DefId,
+ substs: &'tcx Substs<'tcx>,
+ name: ast::Name,
+) -> ImplMethod<'tcx> {
+ assert!(!substs.types.needs_infer());
+
+ let trait_def_id = tcx.trait_id_of_impl(impl_def_id).unwrap();
+ let trait_def = tcx.lookup_trait_def(trait_def_id);
+ let infcx = infer::normalizing_infer_ctxt(tcx, &tcx.tables, ProjectionMode::Any);
+
+ match trait_def.ancestors(impl_def_id).fn_defs(tcx, name).next() {
+ Some(node_item) => {
+ ImplMethod {
+ method: node_item.item,
+ substs: traits::translate_substs(&infcx, impl_def_id, substs, node_item.node),
+ is_provided: node_item.node.is_from_trait(),
+ }
+ }
+ None => {
+ tcx.sess.bug(&format!("method {:?} not found in {:?}", name, impl_def_id))
+ }
+ }
+}
+