diff options
| author | bors <bors@rust-lang.org> | 2021-02-16 22:14:32 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2021-02-16 22:14:32 +0000 |
| commit | 8fe989dd768f5dfdb0fc90933f3f74fa4579fefd (patch) | |
| tree | b343f190d8e1bca405fba9548778befb1986087a /compiler/rustc_plugin_impl | |
| parent | a143517d44cac50b20cbd3a0b579addab40dd399 (diff) | |
| parent | 91d8e59ccaacf7df2af847037d30871ed0bd90b6 (diff) | |
| download | rust-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_plugin_impl')
| -rw-r--r-- | compiler/rustc_plugin_impl/src/build.rs | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/compiler/rustc_plugin_impl/src/build.rs b/compiler/rustc_plugin_impl/src/build.rs index 4796d9a80b6..d5c287fb3bc 100644 --- a/compiler/rustc_plugin_impl/src/build.rs +++ b/compiler/rustc_plugin_impl/src/build.rs @@ -1,7 +1,7 @@ //! Used by `rustc` when compiling a plugin crate. use rustc_hir as hir; -use rustc_hir::def_id::{CrateNum, DefId, LOCAL_CRATE}; +use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, LOCAL_CRATE}; use rustc_hir::itemlikevisit::ItemLikeVisitor; use rustc_middle::ty::query::Providers; use rustc_middle::ty::TyCtxt; @@ -10,14 +10,14 @@ use rustc_span::Span; struct RegistrarFinder<'tcx> { tcx: TyCtxt<'tcx>, - registrars: Vec<(hir::HirId, Span)>, + registrars: Vec<(LocalDefId, Span)>, } impl<'v, 'tcx> ItemLikeVisitor<'v> for RegistrarFinder<'tcx> { fn visit_item(&mut self, item: &hir::Item<'_>) { if let hir::ItemKind::Fn(..) = item.kind { if self.tcx.sess.contains_name(&item.attrs, sym::plugin_registrar) { - self.registrars.push((item.hir_id, item.span)); + self.registrars.push((item.def_id, item.span)); } } } @@ -43,8 +43,8 @@ fn plugin_registrar_fn(tcx: TyCtxt<'_>, cnum: CrateNum) -> Option<DefId> { match finder.registrars.len() { 0 => None, 1 => { - let (hir_id, _) = finder.registrars.pop().unwrap(); - Some(tcx.hir().local_def_id(hir_id).to_def_id()) + let (def_id, _) = finder.registrars.pop().unwrap(); + Some(def_id.to_def_id()) } _ => { let diagnostic = tcx.sess.diagnostic(); |
