about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEduard Burtescu <edy.burt@gmail.com>2015-05-12 07:51:15 +0300
committerEduard Burtescu <edy.burt@gmail.com>2015-05-12 07:51:15 +0300
commitaeb92bab5d63313455e4bfd079ce84712a1a4bac (patch)
tree3d72d6641c3de8182de1309ce732f38c2b3ac7e2
parent8bcb3cb475f0e5223ac63274d229fcbd866f7fe6 (diff)
rustc: rename ty::populate_implementations_for_type_if_necessary to make it clear that it only populates inherent impls.
-rw-r--r--src/librustc/metadata/csearch.rs8
-rw-r--r--src/librustc/metadata/decoder.rs11
-rw-r--r--src/librustc/middle/ty.rs40
-rw-r--r--src/librustc_typeck/check/method/probe.rs2
-rw-r--r--src/librustdoc/clean/inline.rs2
5 files changed, 21 insertions, 42 deletions
diff --git a/src/librustc/metadata/csearch.rs b/src/librustc/metadata/csearch.rs
index 7132ac4895a..4d59bf5d96a 100644
--- a/src/librustc/metadata/csearch.rs
+++ b/src/librustc/metadata/csearch.rs
@@ -313,13 +313,13 @@ pub fn each_impl<F>(cstore: &cstore::CStore,
     decoder::each_impl(&*cdata, callback)
 }
 
-pub fn each_implementation_for_type<F>(cstore: &cstore::CStore,
-                                       def_id: ast::DefId,
-                                       callback: F) where
+pub fn each_inherent_implementation_for_type<F>(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<F>(cstore: &cstore::CStore,
diff --git a/src/librustc/metadata/decoder.rs b/src/librustc/metadata/decoder.rs
index f7fb5d495a4..c5ef97c75f8 100644
--- a/src/librustc/metadata/decoder.rs
+++ b/src/librustc/metadata/decoder.rs
@@ -1338,17 +1338,18 @@ pub fn each_impl<F>(cdata: Cmd, mut callback: F) where
     });
 }
 
-pub fn each_implementation_for_type<F>(cdata: Cmd,
-                                       id: ast::NodeId,
-                                       mut callback: F)
+pub fn each_inherent_implementation_for_type<F>(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 5298c9682b4..38cd6d91a31 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 c94fa037026..6171df218bb 100644
--- a/src/librustc_typeck/check/method/probe.rs
+++ b/src/librustc_typeck/check/method/probe.rs
@@ -371,7 +371,7 @@ impl<'a,'tcx> ProbeContext<'a,'tcx> {
     fn assemble_inherent_impl_candidates_for_type(&mut self, def_id: ast::DefId) {
         // Read the inherent implementation candidates for this type from the
         // metadata if necessary.
-        ty::populate_implementations_for_type_if_necessary(self.tcx(), def_id);
+        ty::populate_inherent_implementations_for_type_if_necessary(self.tcx(), def_id);
 
         if let Some(impl_infos) = self.tcx().inherent_impls.borrow().get(&def_id) {
             for &impl_def_id in &***impl_infos {
diff --git a/src/librustdoc/clean/inline.rs b/src/librustdoc/clean/inline.rs
index 0d59577a6d8..3ce8835b1a8 100644
--- a/src/librustdoc/clean/inline.rs
+++ b/src/librustdoc/clean/inline.rs
@@ -221,7 +221,7 @@ fn build_type(cx: &DocContext, tcx: &ty::ctxt, did: ast::DefId) -> clean::ItemEn
 
 pub fn build_impls(cx: &DocContext, tcx: &ty::ctxt,
                    did: ast::DefId) -> Vec<clean::Item> {
-    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) {