Skip to content

Commit aeb92ba

Browse files
committed
rustc: rename ty::populate_implementations_for_type_if_necessary to make it clear that it only populates inherent impls.
1 parent 8bcb3cb commit aeb92ba

File tree

5 files changed

+21
-42
lines changed

5 files changed

+21
-42
lines changed

src/librustc/metadata/csearch.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -313,13 +313,13 @@ pub fn each_impl<F>(cstore: &cstore::CStore,
313313
decoder::each_impl(&*cdata, callback)
314314
}
315315

316-
pub fn each_implementation_for_type<F>(cstore: &cstore::CStore,
317-
def_id: ast::DefId,
318-
callback: F) where
316+
pub fn each_inherent_implementation_for_type<F>(cstore: &cstore::CStore,
317+
def_id: ast::DefId,
318+
callback: F) where
319319
F: FnMut(ast::DefId),
320320
{
321321
let cdata = cstore.get_crate_data(def_id.krate);
322-
decoder::each_implementation_for_type(&*cdata, def_id.node, callback)
322+
decoder::each_inherent_implementation_for_type(&*cdata, def_id.node, callback)
323323
}
324324

325325
pub fn each_implementation_for_trait<F>(cstore: &cstore::CStore,

src/librustc/metadata/decoder.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1338,17 +1338,18 @@ pub fn each_impl<F>(cdata: Cmd, mut callback: F) where
13381338
});
13391339
}
13401340

1341-
pub fn each_implementation_for_type<F>(cdata: Cmd,
1342-
id: ast::NodeId,
1343-
mut callback: F)
1341+
pub fn each_inherent_implementation_for_type<F>(cdata: Cmd,
1342+
id: ast::NodeId,
1343+
mut callback: F)
13441344
where F: FnMut(ast::DefId),
13451345
{
13461346
let item_doc = lookup_item(id, cdata.data());
13471347
reader::tagged_docs(item_doc,
13481348
tag_items_data_item_inherent_impl,
13491349
|impl_doc| {
1350-
let implementation_def_id = item_def_id(impl_doc, cdata);
1351-
callback(implementation_def_id);
1350+
if reader::maybe_get_doc(impl_doc, tag_item_trait_ref).is_none() {
1351+
callback(item_def_id(impl_doc, cdata));
1352+
}
13521353
true
13531354
});
13541355
}

src/librustc/middle/ty.rs

Lines changed: 9 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6336,10 +6336,10 @@ pub fn populate_implementations_for_primitive_if_necessary(tcx: &ctxt,
63366336
tcx.populated_external_primitive_impls.borrow_mut().insert(primitive_def_id);
63376337
}
63386338

6339-
/// Populates the type context with all the implementations for the given type
6340-
/// if necessary.
6341-
pub fn populate_implementations_for_type_if_necessary(tcx: &ctxt,
6342-
type_id: ast::DefId) {
6339+
/// Populates the type context with all the inherent implementations for
6340+
/// the given type if necessary.
6341+
pub fn populate_inherent_implementations_for_type_if_necessary(tcx: &ctxt,
6342+
type_id: ast::DefId) {
63436343
if type_id.krate == LOCAL_CRATE {
63446344
return
63456345
}
@@ -6348,37 +6348,15 @@ pub fn populate_implementations_for_type_if_necessary(tcx: &ctxt,
63486348
return
63496349
}
63506350

6351-
debug!("populate_implementations_for_type_if_necessary: searching for {:?}", type_id);
6351+
debug!("populate_inherent_implementations_for_type_if_necessary: searching for {:?}", type_id);
63526352

63536353
let mut inherent_impls = Vec::new();
6354-
csearch::each_implementation_for_type(&tcx.sess.cstore, type_id, |impl_def_id| {
6355-
let impl_items = csearch::get_impl_items(&tcx.sess.cstore, impl_def_id);
6356-
6357-
// Record the implementation, if needed
6358-
if let Some(trait_ref) = csearch::get_impl_trait(tcx, impl_def_id) {
6359-
let trait_def = lookup_trait_def(tcx, trait_ref.def_id);
6360-
trait_def.record_impl(tcx, impl_def_id, trait_ref);
6361-
} else {
6362-
inherent_impls.push(impl_def_id);
6363-
}
6364-
6365-
// For any methods that use a default implementation, add them to
6366-
// the map. This is a bit unfortunate.
6367-
for impl_item_def_id in &impl_items {
6368-
let method_def_id = impl_item_def_id.def_id();
6369-
match impl_or_trait_item(tcx, method_def_id) {
6370-
MethodTraitItem(method) => {
6371-
if let Some(source) = method.provided_source {
6372-
tcx.provided_method_sources
6373-
.borrow_mut()
6374-
.insert(method_def_id, source);
6375-
}
6376-
}
6377-
_ => {}
6378-
}
6379-
}
6354+
csearch::each_inherent_implementation_for_type(&tcx.sess.cstore, type_id, |impl_def_id| {
6355+
// Record the implementation.
6356+
inherent_impls.push(impl_def_id);
63806357

63816358
// Store the implementation info.
6359+
let impl_items = csearch::get_impl_items(&tcx.sess.cstore, impl_def_id);
63826360
tcx.impl_items.borrow_mut().insert(impl_def_id, impl_items);
63836361
});
63846362

src/librustc_typeck/check/method/probe.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ impl<'a,'tcx> ProbeContext<'a,'tcx> {
371371
fn assemble_inherent_impl_candidates_for_type(&mut self, def_id: ast::DefId) {
372372
// Read the inherent implementation candidates for this type from the
373373
// metadata if necessary.
374-
ty::populate_implementations_for_type_if_necessary(self.tcx(), def_id);
374+
ty::populate_inherent_implementations_for_type_if_necessary(self.tcx(), def_id);
375375

376376
if let Some(impl_infos) = self.tcx().inherent_impls.borrow().get(&def_id) {
377377
for &impl_def_id in &***impl_infos {

src/librustdoc/clean/inline.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ fn build_type(cx: &DocContext, tcx: &ty::ctxt, did: ast::DefId) -> clean::ItemEn
221221

222222
pub fn build_impls(cx: &DocContext, tcx: &ty::ctxt,
223223
did: ast::DefId) -> Vec<clean::Item> {
224-
ty::populate_implementations_for_type_if_necessary(tcx, did);
224+
ty::populate_inherent_implementations_for_type_if_necessary(tcx, did);
225225
let mut impls = Vec::new();
226226

227227
match tcx.inherent_impls.borrow().get(&did) {

0 commit comments

Comments
 (0)