Skip to content

Commit a2b9441

Browse files
committed
Return hir_attr_map query
1 parent fbe9850 commit a2b9441

3 files changed

Lines changed: 12 additions & 5 deletions

File tree

compiler/rustc_middle/src/hir/map.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use rustc_hir_pretty as pprust_hir;
1818
use rustc_span::def_id::StableCrateId;
1919
use rustc_span::{ErrorGuaranteed, Ident, Span, Symbol, kw, with_metavar_spans};
2020

21-
use crate::hir::{ModuleItems, nested_filter};
21+
use crate::hir::{MaybeOwner, ModuleItems, nested_filter};
2222
use crate::middle::debugger_visualizer::DebuggerVisualizerFile;
2323
use crate::query::{IntoQueryKey, LocalCrate};
2424
use crate::ty::TyCtxt;
@@ -115,10 +115,6 @@ impl<'tcx> TyCtxt<'tcx> {
115115
self.owner(id.def_id).as_owner().map(|o| &o.delayed_lints)
116116
}
117117

118-
pub fn hir_attr_map(self, id: OwnerId) -> &'tcx AttributeMap<'tcx> {
119-
self.owner(id.def_id).as_owner().map_or(AttributeMap::EMPTY, |o| &o.attrs)
120-
}
121-
122118
pub fn in_scope_traits_map(
123119
self,
124120
id: OwnerId,

compiler/rustc_middle/src/hir/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,8 @@ pub fn provide(providers: &mut Providers) {
434434
providers.hir_crate_items = map::hir_crate_items;
435435
providers.crate_hash = map::crate_hash;
436436
providers.hir_module_items = map::hir_module_items;
437+
providers.hir_attr_map =
438+
|tcx, id| tcx.owner(id.def_id).as_owner().map_or(AttributeMap::EMPTY, |o| &o.attrs);
437439
// Serves as an entry point for getting `MaybeOwner`. As owner can either be in
438440
// `owners` of `hir_crate` or it can be delayed AST owner (i.e., delegations)
439441
// we need to firstly check in `hir_crate` and then delayed AST owners.

compiler/rustc_middle/src/queries.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,15 @@ rustc_queries! {
251251
desc { "getting HIR parent of `{}`", tcx.def_path_str(key) }
252252
}
253253

254+
/// Gives access to the HIR attributes inside the HIR owner `key`.
255+
///
256+
/// This can be conveniently accessed by `tcx.hir_*` methods.
257+
/// Avoid calling this query directly.
258+
query hir_attr_map(key: hir::OwnerId) -> &'tcx hir::AttributeMap<'tcx> {
259+
desc { "getting HIR owner attributes in `{}`", tcx.def_path_str(key) }
260+
feedable
261+
}
262+
254263
/// Returns the *default* of the const pararameter given by `DefId`.
255264
///
256265
/// E.g., given `struct Ty<const N: usize = 3>;` this returns `3` for `N`.

0 commit comments

Comments
 (0)