diff --git a/src/librustc/metadata/csearch.rs b/src/librustc/metadata/csearch.rs index 7132ac4895aa1d60055871301ba4c5cc8c94041e..4d59bf5d96ab4bcb4496b503b0f0e890ef0a2978 100644 --- a/src/librustc/metadata/csearch.rs +++ b/src/librustc/metadata/csearch.rs @@ -313,13 +313,13 @@ pub fn each_impl(cstore: &cstore::CStore, decoder::each_impl(&*cdata, callback) } -pub fn each_implementation_for_type(cstore: &cstore::CStore, - def_id: ast::DefId, - callback: F) where +pub fn each_inherent_implementation_for_type(cstore: &cstore::CStore, + def_id: ast::DefId, + callback: F) where F: FnMut(ast::DefId), { let cdata = cstore.get_crate_data(def_id.krate); - decoder::each_implementation_for_type(&*cdata, def_id.node, callback) + decoder::each_inherent_implementation_for_type(&*cdata, def_id.node, callback) } pub fn each_implementation_for_trait(cstore: &cstore::CStore, diff --git a/src/librustc/metadata/decoder.rs b/src/librustc/metadata/decoder.rs index f7fb5d495a4572f4fb31855ac22e216df0854ff5..c5ef97c75f8781ae3cef8a136b8cedb8ee1ab19d 100644 --- a/src/librustc/metadata/decoder.rs +++ b/src/librustc/metadata/decoder.rs @@ -1338,17 +1338,18 @@ pub fn each_impl(cdata: Cmd, mut callback: F) where }); } -pub fn each_implementation_for_type(cdata: Cmd, - id: ast::NodeId, - mut callback: F) +pub fn each_inherent_implementation_for_type(cdata: Cmd, + id: ast::NodeId, + mut callback: F) where F: FnMut(ast::DefId), { let item_doc = lookup_item(id, cdata.data()); reader::tagged_docs(item_doc, tag_items_data_item_inherent_impl, |impl_doc| { - let implementation_def_id = item_def_id(impl_doc, cdata); - callback(implementation_def_id); + if reader::maybe_get_doc(impl_doc, tag_item_trait_ref).is_none() { + callback(item_def_id(impl_doc, cdata)); + } true }); } diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index 5298c9682b48c067ceae2c473833c4e7ed159395..38cd6d91a31e83ba38eb31cea1a3d4cd3c629298 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -6336,10 +6336,10 @@ pub fn populate_implementations_for_primitive_if_necessary(tcx: &ctxt, tcx.populated_external_primitive_impls.borrow_mut().insert(primitive_def_id); } -/// Populates the type context with all the implementations for the given type -/// if necessary. -pub fn populate_implementations_for_type_if_necessary(tcx: &ctxt, - type_id: ast::DefId) { +/// Populates the type context with all the inherent implementations for +/// the given type if necessary. +pub fn populate_inherent_implementations_for_type_if_necessary(tcx: &ctxt, + type_id: ast::DefId) { if type_id.krate == LOCAL_CRATE { return } @@ -6348,37 +6348,15 @@ pub fn populate_implementations_for_type_if_necessary(tcx: &ctxt, return } - debug!("populate_implementations_for_type_if_necessary: searching for {:?}", type_id); + debug!("populate_inherent_implementations_for_type_if_necessary: searching for {:?}", type_id); let mut inherent_impls = Vec::new(); - csearch::each_implementation_for_type(&tcx.sess.cstore, type_id, |impl_def_id| { - let impl_items = csearch::get_impl_items(&tcx.sess.cstore, impl_def_id); - - // Record the implementation, if needed - if let Some(trait_ref) = csearch::get_impl_trait(tcx, impl_def_id) { - let trait_def = lookup_trait_def(tcx, trait_ref.def_id); - trait_def.record_impl(tcx, impl_def_id, trait_ref); - } else { - inherent_impls.push(impl_def_id); - } - - // For any methods that use a default implementation, add them to - // the map. This is a bit unfortunate. - for impl_item_def_id in &impl_items { - let method_def_id = impl_item_def_id.def_id(); - match impl_or_trait_item(tcx, method_def_id) { - MethodTraitItem(method) => { - if let Some(source) = method.provided_source { - tcx.provided_method_sources - .borrow_mut() - .insert(method_def_id, source); - } - } - _ => {} - } - } + csearch::each_inherent_implementation_for_type(&tcx.sess.cstore, type_id, |impl_def_id| { + // Record the implementation. + inherent_impls.push(impl_def_id); // Store the implementation info. + let impl_items = csearch::get_impl_items(&tcx.sess.cstore, impl_def_id); tcx.impl_items.borrow_mut().insert(impl_def_id, impl_items); }); diff --git a/src/librustc_typeck/check/method/probe.rs b/src/librustc_typeck/check/method/probe.rs index c94fa03702681bcb5fdd52131ab98cf7b8489c08..6171df218bb60a468ecec9570881f0c9a7a105d2 100644 --- a/src/librustc_typeck/check/method/probe.rs +++ b/src/librustc_typeck/check/method/probe.rs @@ -371,7 +371,7 @@ fn assemble_inherent_impl_for_primitive(&mut self, lang_def_id: Option clean::ItemEn pub fn build_impls(cx: &DocContext, tcx: &ty::ctxt, did: ast::DefId) -> Vec { - ty::populate_implementations_for_type_if_necessary(tcx, did); + ty::populate_inherent_implementations_for_type_if_necessary(tcx, did); let mut impls = Vec::new(); match tcx.inherent_impls.borrow().get(&did) {