Skip to content

Do not query the HIR directly in opt_associated_item. #80889

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 11, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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