Use Iterator::find in associated_item search

This commit is contained in:
Taylor Cramer 2017-03-21 00:09:20 -07:00
parent 4cd28a7387
commit 8e58d9eb8f
1 changed files with 6 additions and 8 deletions

View File

@ -2585,26 +2585,24 @@ fn associated_item<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId)
let parent_item = tcx.hir.expect_item(parent_id); let parent_item = tcx.hir.expect_item(parent_id);
match parent_item.node { match parent_item.node {
hir::ItemImpl(.., ref impl_trait_ref, _, ref impl_item_refs) => { hir::ItemImpl(.., ref impl_trait_ref, _, ref impl_item_refs) => {
for impl_item_ref in impl_item_refs { if let Some(impl_item_ref) = impl_item_refs.iter().find(|i| i.id.node_id == id) {
let assoc_item = let assoc_item =
tcx.associated_item_from_impl_item_ref(parent_def_id, tcx.associated_item_from_impl_item_ref(parent_def_id,
impl_trait_ref.is_some(), impl_trait_ref.is_some(),
impl_item_ref); impl_item_ref);
if assoc_item.def_id == def_id { debug_assert_eq!(assoc_item.def_id, def_id);
return assoc_item; return assoc_item;
} }
} }
}
hir::ItemTrait(.., ref trait_item_refs) => { hir::ItemTrait(.., ref trait_item_refs) => {
for trait_item_ref in trait_item_refs { if let Some(trait_item_ref) = trait_item_refs.iter().find(|i| i.id.node_id == id) {
let assoc_item = let assoc_item =
tcx.associated_item_from_trait_item_ref(parent_def_id, trait_item_ref); tcx.associated_item_from_trait_item_ref(parent_def_id, trait_item_ref);
if assoc_item.def_id == def_id { debug_assert_eq!(assoc_item.def_id, def_id);
return assoc_item; return assoc_item;
} }
} }
}
ref r => { ref r => {
panic!("unexpected container of associated items: {:?}", r) panic!("unexpected container of associated items: {:?}", r)