Skip to content

Commit

Permalink
Auto merge of #80889 - cjgillot:asa, r=oli-obk
Browse files Browse the repository at this point in the history
Do not query the HIR directly in `opt_associated_item`.

Papercut found by `@Aaron1011.`
  • Loading branch information
bors committed Jan 11, 2021
2 parents a2cd91c + 21e1963 commit 6526e5c
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions compiler/rustc_middle/src/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2897,19 +2897,11 @@ impl<'tcx> TyCtxt<'tcx> {
}

pub fn opt_associated_item(self, def_id: DefId) -> Option<&'tcx AssocItem> {
let is_associated_item = if let Some(def_id) = def_id.as_local() {
matches!(
self.hir().get(self.hir().local_def_id_to_hir_id(def_id)),
Node::TraitItem(_) | Node::ImplItem(_)
)
if let DefKind::AssocConst | DefKind::AssocFn | DefKind::AssocTy = self.def_kind(def_id) {
Some(self.associated_item(def_id))
} else {
matches!(
self.def_kind(def_id),
DefKind::AssocConst | DefKind::AssocFn | DefKind::AssocTy
)
};

is_associated_item.then(|| self.associated_item(def_id))
None
}
}

pub fn field_index(self, hir_id: hir::HirId, typeck_results: &TypeckResults<'_>) -> usize {
Expand Down

0 comments on commit 6526e5c

Please sign in to comment.