Skip to content

Commit 7d1ac19

Browse files
Use associated_items query in impl overlap check
This reduces the number of `associated_item` queries done here.
1 parent f3e8947 commit 7d1ac19

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

src/librustc_typeck/coherence/inherent_impls_overlap.rs

+10-12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::namespace::Namespace;
22
use rustc::traits::{self, IntercrateMode};
3-
use rustc::ty::TyCtxt;
3+
use rustc::ty::{AssocItem, TyCtxt};
44
use rustc_errors::struct_span_err;
55
use rustc_hir as hir;
66
use rustc_hir::def_id::{CrateNum, DefId, LOCAL_CRATE};
@@ -23,32 +23,30 @@ impl InherentOverlapChecker<'tcx> {
2323
impl2: DefId,
2424
overlap: traits::OverlapResult<'_>,
2525
) {
26-
let name_and_namespace = |def_id| {
27-
let item = self.tcx.associated_item(def_id);
28-
(item.ident.modern(), Namespace::from(item.kind))
29-
};
26+
let name_and_namespace =
27+
|assoc: &AssocItem| (assoc.ident.modern(), Namespace::from(assoc.kind));
3028

31-
let impl_items1 = self.tcx.associated_item_def_ids(impl1);
32-
let impl_items2 = self.tcx.associated_item_def_ids(impl2);
29+
let impl_items1 = self.tcx.associated_items(impl1);
30+
let impl_items2 = self.tcx.associated_items(impl2);
3331

34-
for &item1 in &impl_items1[..] {
32+
for item1 in &impl_items1[..] {
3533
let (name, namespace) = name_and_namespace(item1);
3634

37-
for &item2 in &impl_items2[..] {
35+
for item2 in &impl_items2[..] {
3836
if (name, namespace) == name_and_namespace(item2) {
3937
let mut err = struct_span_err!(
4038
self.tcx.sess,
41-
self.tcx.span_of_impl(item1).unwrap(),
39+
self.tcx.span_of_impl(item1.def_id).unwrap(),
4240
E0592,
4341
"duplicate definitions with name `{}`",
4442
name
4543
);
4644
err.span_label(
47-
self.tcx.span_of_impl(item1).unwrap(),
45+
self.tcx.span_of_impl(item1.def_id).unwrap(),
4846
format!("duplicate definitions for `{}`", name),
4947
);
5048
err.span_label(
51-
self.tcx.span_of_impl(item2).unwrap(),
49+
self.tcx.span_of_impl(item2.def_id).unwrap(),
5250
format!("other definition for `{}`", name),
5351
);
5452

0 commit comments

Comments
 (0)