about summary refs log tree commit diff
path: root/compiler/rustc_infer/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2021-02-16 22:14:32 +0000
committerbors <bors@rust-lang.org>2021-02-16 22:14:32 +0000
commit8fe989dd768f5dfdb0fc90933f3f74fa4579fefd (patch)
treeb343f190d8e1bca405fba9548778befb1986087a /compiler/rustc_infer/src
parenta143517d44cac50b20cbd3a0b579addab40dd399 (diff)
parent91d8e59ccaacf7df2af847037d30871ed0bd90b6 (diff)
downloadrust-8fe989dd768f5dfdb0fc90933f3f74fa4579fefd.tar.gz
rust-8fe989dd768f5dfdb0fc90933f3f74fa4579fefd.zip
Auto merge of #81611 - cjgillot:meowner, r=estebank
Only store a LocalDefId in some HIR nodes

Some HIR nodes are guaranteed to be HIR owners: Item, TraitItem, ImplItem, ForeignItem and MacroDef.
As a consequence, we do not need to store the `HirId`'s `local_id`, and we can directly store a `LocalDefId`.

This allows to avoid a bit of the dance with `tcx.hir().local_def_id` and `tcx.hir().local_def_id_to_hir_id` mappings.
Diffstat (limited to 'compiler/rustc_infer/src')
-rw-r--r--compiler/rustc_infer/src/infer/error_reporting/nice_region_error/static_impl_trait.rs22
1 files changed, 9 insertions, 13 deletions
diff --git a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/static_impl_trait.rs b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/static_impl_trait.rs
index c6ae71ba330..fa0d5b83013 100644
--- a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/static_impl_trait.rs
+++ b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/static_impl_trait.rs
@@ -7,10 +7,7 @@ use crate::traits::{ObligationCauseCode, UnifyReceiverContext};
 use rustc_errors::{struct_span_err, Applicability, DiagnosticBuilder, ErrorReported};
 use rustc_hir::def_id::DefId;
 use rustc_hir::intravisit::{walk_ty, ErasedMap, NestedVisitorMap, Visitor};
-use rustc_hir::{
-    self as hir, GenericBound, ImplItem, Item, ItemKind, Lifetime, LifetimeName, Node, TraitItem,
-    TyKind,
-};
+use rustc_hir::{self as hir, GenericBound, Item, ItemKind, Lifetime, LifetimeName, Node, TyKind};
 use rustc_middle::ty::{self, AssocItemContainer, RegionKind, Ty, TypeFoldable, TypeVisitor};
 use rustc_span::symbol::Ident;
 use rustc_span::{MultiSpan, Span};
@@ -234,7 +231,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
             }
             match fn_return.kind {
                 TyKind::OpaqueDef(item_id, _) => {
-                    let item = tcx.hir().item(item_id.id);
+                    let item = tcx.hir().item(item_id);
                     let opaque = if let ItemKind::OpaqueTy(opaque) = &item.kind {
                         opaque
                     } else {
@@ -343,17 +340,17 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
     ) -> Option<(Ident, &'tcx hir::Ty<'tcx>)> {
         let tcx = self.tcx();
         match tcx.hir().get_if_local(def_id) {
-            Some(Node::ImplItem(ImplItem { ident, hir_id, .. })) => {
-                match tcx.hir().find(tcx.hir().get_parent_item(*hir_id)) {
+            Some(Node::ImplItem(impl_item)) => {
+                match tcx.hir().find(tcx.hir().get_parent_item(impl_item.hir_id())) {
                     Some(Node::Item(Item {
                         kind: ItemKind::Impl(hir::Impl { self_ty, .. }),
                         ..
-                    })) => Some((*ident, self_ty)),
+                    })) => Some((impl_item.ident, self_ty)),
                     _ => None,
                 }
             }
-            Some(Node::TraitItem(TraitItem { ident, hir_id, .. })) => {
-                let parent_id = tcx.hir().get_parent_item(*hir_id);
+            Some(Node::TraitItem(trait_item)) => {
+                let parent_id = tcx.hir().get_parent_item(trait_item.hir_id());
                 match tcx.hir().find(parent_id) {
                     Some(Node::Item(Item { kind: ItemKind::Trait(..), .. })) => {
                         // The method being called is defined in the `trait`, but the `'static`
@@ -364,8 +361,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
                             .hir()
                             .trait_impls(trait_did)
                             .iter()
-                            .filter_map(|impl_node| {
-                                let impl_did = tcx.hir().local_def_id(*impl_node);
+                            .filter_map(|&impl_did| {
                                 match tcx.hir().get_if_local(impl_did.to_def_id()) {
                                     Some(Node::Item(Item {
                                         kind: ItemKind::Impl(hir::Impl { self_ty, .. }),
@@ -389,7 +385,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
                             })
                             .next()
                         {
-                            Some(self_ty) => Some((*ident, self_ty)),
+                            Some(self_ty) => Some((trait_item.ident, self_ty)),
                             _ => None,
                         }
                     }