Skip to content

Commit 932d251

Browse files
committed
query for def_span
1 parent ace517d commit 932d251

File tree

4 files changed

+20
-16
lines changed

4 files changed

+20
-16
lines changed

src/librustc/middle/cstore.rs

-2
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,6 @@ pub trait CrateStore {
181181
fn crate_data_as_rc_any(&self, krate: CrateNum) -> Rc<Any>;
182182

183183
// item info
184-
fn def_span(&self, sess: &Session, def: DefId) -> Span;
185184
fn stability(&self, def: DefId) -> Option<attr::Stability>;
186185
fn deprecation(&self, def: DefId) -> Option<attr::Deprecation>;
187186
fn visibility(&self, def: DefId) -> ty::Visibility;
@@ -312,7 +311,6 @@ impl CrateStore for DummyCrateStore {
312311
fn crate_data_as_rc_any(&self, krate: CrateNum) -> Rc<Any>
313312
{ bug!("crate_data_as_rc_any") }
314313
// item info
315-
fn def_span(&self, sess: &Session, def: DefId) -> Span { bug!("def_span") }
316314
fn stability(&self, def: DefId) -> Option<attr::Stability> { bug!("stability") }
317315
fn deprecation(&self, def: DefId) -> Option<attr::Deprecation> { bug!("deprecation") }
318316
fn visibility(&self, def: DefId) -> ty::Visibility { bug!("visibility") }

src/librustc/ty/maps.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,12 @@ impl<'tcx> QueryDescription for queries::describe_def<'tcx> {
271271
}
272272
}
273273

274+
impl<'tcx> QueryDescription for queries::def_span<'tcx> {
275+
fn describe(_: TyCtxt, _: DefId) -> String {
276+
bug!("def_span")
277+
}
278+
}
279+
274280
macro_rules! define_maps {
275281
(<$tcx:tt>
276282
$($(#[$attr:meta])*
@@ -547,7 +553,8 @@ define_maps! { <'tcx>
547553
pub def_symbol_name: SymbolName(DefId) -> ty::SymbolName,
548554
pub symbol_name: symbol_name_dep_node(ty::Instance<'tcx>) -> ty::SymbolName,
549555

550-
pub describe_def: meta_data_node(DefId) -> Option<Def>
556+
pub describe_def: meta_data_node(DefId) -> Option<Def>,
557+
pub def_span: meta_data_node(DefId) -> Span
551558
}
552559

553560
fn coherent_trait_dep_node((_, def_id): (CrateNum, DefId)) -> DepNode<DefId> {

src/librustc/ty/mod.rs

+11-8
Original file line numberDiff line numberDiff line change
@@ -2265,14 +2265,6 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
22652265
}
22662266
}
22672267

2268-
pub fn def_span(self, def_id: DefId) -> Span {
2269-
if let Some(id) = self.hir.as_local_node_id(def_id) {
2270-
self.hir.span(id)
2271-
} else {
2272-
self.sess.cstore.def_span(&self.sess, def_id)
2273-
}
2274-
}
2275-
22762268
pub fn vis_is_accessible_from(self, vis: Visibility, block: NodeId) -> bool {
22772269
vis.is_accessible_from(self.hir.local_def_id(self.hir.get_module_parent(block)), self)
22782270
}
@@ -2675,12 +2667,23 @@ fn associated_item_def_ids<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
26752667
Rc::new(vec)
26762668
}
26772669

2670+
fn def_span<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> Span {
2671+
match tcx.hir.span_if_local(def_id) {
2672+
Some(span) => span,
2673+
None => {
2674+
let node_id = tcx.sess.cstore.item_body(tcx, def_id).id().node_id;
2675+
tcx.hir.span(node_id)
2676+
},
2677+
}
2678+
}
2679+
26782680
pub fn provide(providers: &mut ty::maps::Providers) {
26792681
*providers = ty::maps::Providers {
26802682
associated_item,
26812683
associated_item_def_ids,
26822684
adt_sized_constraint,
26832685
adt_dtorck_constraint,
2686+
def_span,
26842687
..*providers
26852688
};
26862689
}

src/librustc_metadata/cstore_impl.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -114,18 +114,14 @@ provide! { <'tcx> tcx, def_id, cdata
114114
inherent_impls => { Rc::new(cdata.get_inherent_implementations_for_type(def_id.index)) }
115115
is_foreign_item => { cdata.is_foreign_item(def_id.index) }
116116
describe_def => { cdata.get_def(def_id.index) }
117+
def_span => { cdata.get_span(def_id.index, &tcx.sess) }
117118
}
118119

119120
impl CrateStore for cstore::CStore {
120121
fn crate_data_as_rc_any(&self, krate: CrateNum) -> Rc<Any> {
121122
self.get_crate_data(krate)
122123
}
123124

124-
fn def_span(&self, sess: &Session, def: DefId) -> Span {
125-
self.dep_graph.read(DepNode::MetaData(def));
126-
self.get_crate_data(def.krate).get_span(def.index, sess)
127-
}
128-
129125
fn stability(&self, def: DefId) -> Option<attr::Stability> {
130126
self.dep_graph.read(DepNode::MetaData(def));
131127
self.get_crate_data(def.krate).get_stability(def.index)

0 commit comments

Comments
 (0)