Skip to content

Commit 71b5666

Browse files
committed
Introduce a query for HIR spans.
1 parent c6acd0f commit 71b5666

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

src/librustc_middle/hir/map/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -828,7 +828,7 @@ impl<'hir> Map<'hir> {
828828
}
829829

830830
pub fn span(&self, hir_id: HirId) -> Span {
831-
self.tcx.index_hir(LOCAL_CRATE).map[hir_id.owner].spans[hir_id.local_id].unwrap()
831+
self.tcx.hir_owner_spans(hir_id.owner)[hir_id.local_id].unwrap()
832832
}
833833

834834
pub fn span_if_local(&self, id: DefId) -> Option<Span> {

src/librustc_middle/hir/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,5 +79,6 @@ pub fn provide(providers: &mut Providers<'_>) {
7979
};
8080
providers.hir_owner = |tcx, id| tcx.index_hir(LOCAL_CRATE).map[id].signature;
8181
providers.hir_owner_nodes = |tcx, id| tcx.index_hir(LOCAL_CRATE).map[id].with_bodies.as_deref();
82+
providers.hir_owner_spans = |tcx, id| &tcx.index_hir(LOCAL_CRATE).map[id].spans;
8283
map::provide(providers);
8384
}

src/librustc_middle/query/mod.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,15 @@ rustc_queries! {
8989
desc { |tcx| "HIR owner items in `{}`", tcx.def_path_str(key.to_def_id()) }
9090
}
9191

92+
// Gives access to the HIR spans inside the HIR owner `key`.
93+
//
94+
// This can be conveniently accessed by methods on `tcx.hir()`.
95+
// Avoid calling this query directly.
96+
query hir_owner_spans(key: LocalDefId) -> &'tcx IndexVec<ItemLocalId, Option<Span>> {
97+
eval_always
98+
desc { |tcx| "HIR owner spans in `{}`", tcx.def_path_str(key.to_def_id()) }
99+
}
100+
92101
/// Records the type of every item.
93102
query type_of(key: DefId) -> Ty<'tcx> {
94103
desc { |tcx| "computing type of `{}`", tcx.def_path_str(key) }

0 commit comments

Comments
 (0)