Skip to content

Commit 833b915

Browse files
committed
Make encode_attrs use opt_local_def_id_to_hir_id so we can feed it with None for definitions that have no HIR
1 parent f722b24 commit 833b915

File tree

4 files changed

+12
-9
lines changed

4 files changed

+12
-9
lines changed

compiler/rustc_metadata/src/rmeta/encoder.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,8 +1137,8 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
11371137
is_doc_hidden: false,
11381138
};
11391139
let attr_iter = tcx
1140-
.hir()
1141-
.attrs(tcx.hir().local_def_id_to_hir_id(def_id))
1140+
.opt_local_def_id_to_hir_id(def_id)
1141+
.map_or(Default::default(), |hir_id| tcx.hir().attrs(hir_id))
11421142
.iter()
11431143
.filter(|attr| analyze_attr(attr, &mut state));
11441144

compiler/rustc_middle/src/hir/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,13 +121,13 @@ pub fn provide(providers: &mut Providers) {
121121
let node = owner.node();
122122
Some(Owner { node, hash_without_bodies: owner.nodes.hash_without_bodies })
123123
};
124-
providers.local_def_id_to_hir_id = |tcx, id| {
124+
providers.opt_local_def_id_to_hir_id = |tcx, id| {
125125
let owner = tcx.hir_crate(()).owners[id].map(|_| ());
126-
match owner {
126+
Some(match owner {
127127
MaybeOwner::Owner(_) => HirId::make_owner(id),
128128
MaybeOwner::Phantom => bug!("No HirId for {:?}", id),
129129
MaybeOwner::NonOwner(hir_id) => hir_id,
130-
}
130+
})
131131
};
132132
providers.hir_owner_nodes = |tcx, id| tcx.hir_crate(()).owners[id.def_id].map(|i| &i.nodes);
133133
providers.hir_owner_parent = |tcx, id| {

compiler/rustc_middle/src/query/mod.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,10 @@ rustc_queries! {
8585
desc { |tcx| "getting HIR owner of `{}`", tcx.def_path_str(key.to_def_id()) }
8686
}
8787

88-
/// Gives access to the HIR ID for the given `LocalDefId` owner `key`.
88+
/// Gives access to the HIR ID for the given `LocalDefId` owner `key` if any.
8989
///
90-
/// This can be conveniently accessed by methods on `tcx.hir()`.
91-
/// Avoid calling this query directly.
92-
query local_def_id_to_hir_id(key: LocalDefId) -> hir::HirId {
90+
/// Definitions that were generated with no HIR, would be feeded to return `None`.
91+
query opt_local_def_id_to_hir_id(key: LocalDefId) -> Option<hir::HirId>{
9392
desc { |tcx| "getting HIR ID of `{}`", tcx.def_path_str(key.to_def_id()) }
9493
}
9594

compiler/rustc_middle/src/ty/context.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2428,6 +2428,10 @@ impl<'tcx> TyCtxt<'tcx> {
24282428
)
24292429
}
24302430

2431+
pub fn local_def_id_to_hir_id(self, local_def_id: LocalDefId) -> HirId {
2432+
self.opt_local_def_id_to_hir_id(local_def_id).unwrap()
2433+
}
2434+
24312435
pub fn trait_solver_next(self) -> bool {
24322436
self.sess.opts.unstable_opts.trait_solver == rustc_session::config::TraitSolver::Next
24332437
}

0 commit comments

Comments
 (0)