Skip to content

Commit

Permalink
Use associated_items query in impl overlap check
Browse files Browse the repository at this point in the history
This reduces the number of `associated_item` queries done here.
  • Loading branch information
jonas-schievink committed Feb 8, 2020
1 parent 66fd4e6 commit f416573
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions src/librustc_typeck/coherence/inherent_impls_overlap.rs
Expand Up @@ -23,32 +23,30 @@ impl InherentOverlapChecker<'tcx> {
impl2: DefId,
overlap: traits::OverlapResult<'_>,
) {
let name_and_namespace = |def_id| {
let item = self.tcx.associated_item(def_id);
(item.ident.modern(), Namespace::from(item.kind))
};
let name_and_namespace =
|assoc: &AssocItem| (assoc.ident.modern(), Namespace::from(assoc.kind));

let impl_items1 = self.tcx.associated_item_def_ids(impl1);
let impl_items2 = self.tcx.associated_item_def_ids(impl2);
let impl_items1 = self.tcx.associated_items(impl1);
let impl_items2 = self.tcx.associated_items(impl2);

for &item1 in &impl_items1[..] {
for item1 in &impl_items1[..] {
let (name, namespace) = name_and_namespace(item1);

for &item2 in &impl_items2[..] {
for item2 in &impl_items2[..] {
if (name, namespace) == name_and_namespace(item2) {
let mut err = struct_span_err!(
self.tcx.sess,
self.tcx.span_of_impl(item1).unwrap(),
self.tcx.span_of_impl(item1.def_id).unwrap(),
E0592,
"duplicate definitions with name `{}`",
name
);
err.span_label(
self.tcx.span_of_impl(item1).unwrap(),
self.tcx.span_of_impl(item1.def_id).unwrap(),
format!("duplicate definitions for `{}`", name),
);
err.span_label(
self.tcx.span_of_impl(item2).unwrap(),
self.tcx.span_of_impl(item2.def_id).unwrap(),
format!("other definition for `{}`", name),
);

Expand Down

0 comments on commit f416573

Please sign in to comment.