Skip to content

Commit 8e58d9e

Browse files
committed
Use Iterator::find in associated_item search
1 parent 4cd28a7 commit 8e58d9e

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

src/librustc/ty/mod.rs

+6-8
Original file line numberDiff line numberDiff line change
@@ -2585,24 +2585,22 @@ fn associated_item<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId)
25852585
let parent_item = tcx.hir.expect_item(parent_id);
25862586
match parent_item.node {
25872587
hir::ItemImpl(.., ref impl_trait_ref, _, ref impl_item_refs) => {
2588-
for impl_item_ref in impl_item_refs {
2588+
if let Some(impl_item_ref) = impl_item_refs.iter().find(|i| i.id.node_id == id) {
25892589
let assoc_item =
25902590
tcx.associated_item_from_impl_item_ref(parent_def_id,
25912591
impl_trait_ref.is_some(),
25922592
impl_item_ref);
2593-
if assoc_item.def_id == def_id {
2594-
return assoc_item;
2595-
}
2593+
debug_assert_eq!(assoc_item.def_id, def_id);
2594+
return assoc_item;
25962595
}
25972596
}
25982597

25992598
hir::ItemTrait(.., ref trait_item_refs) => {
2600-
for trait_item_ref in trait_item_refs {
2599+
if let Some(trait_item_ref) = trait_item_refs.iter().find(|i| i.id.node_id == id) {
26012600
let assoc_item =
26022601
tcx.associated_item_from_trait_item_ref(parent_def_id, trait_item_ref);
2603-
if assoc_item.def_id == def_id {
2604-
return assoc_item;
2605-
}
2602+
debug_assert_eq!(assoc_item.def_id, def_id);
2603+
return assoc_item;
26062604
}
26072605
}
26082606

0 commit comments

Comments
 (0)