about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2021-01-11 14:54:52 +0000
committerbors <bors@rust-lang.org>2021-01-11 14:54:52 +0000
commit6526e5c772f2da07db745c94ca6bb0a591a39ba4 (patch)
tree9030d255f1d41c67091c7db744e1405ec4d81da1
parenta2cd91ceb0f156cb442d75e12dc77c3d064cdde4 (diff)
parent21e1963e9c569ffacdeb1e8125283dd7975f58ec (diff)
downloadrust-6526e5c772f2da07db745c94ca6bb0a591a39ba4.tar.gz
rust-6526e5c772f2da07db745c94ca6bb0a591a39ba4.zip
Auto merge of #80889 - cjgillot:asa, r=oli-obk
Do not query the HIR directly in `opt_associated_item`.

Papercut found by `@Aaron1011.`
-rw-r--r--compiler/rustc_middle/src/ty/mod.rs16
1 files changed, 4 insertions, 12 deletions
diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs
index 59a3ac94634..863423b91a6 100644
--- a/compiler/rustc_middle/src/ty/mod.rs
+++ b/compiler/rustc_middle/src/ty/mod.rs
@@ -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 {