Skip to content

Commit d76353d

Browse files
authored
Rollup merge of rust-lang#41534 - achernyak:master, r=eddyb
query for describe_def Resolves `fn describe_def(&self, def: DefId) -> Option<Def>;` of rust-lang#41417. r? @nikomatsakis I would greatly appreciate a review. I hope I covered everything described in the pr.
2 parents cada869 + e24003f commit d76353d

File tree

6 files changed

+20
-13
lines changed

6 files changed

+20
-13
lines changed

src/librustc/middle/cstore.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
// are *mostly* used as a part of that interface, but these should
2323
// probably get a better home if someone can find one.
2424

25-
use hir::def::{self, Def};
25+
use hir::def;
2626
use hir::def_id::{CrateNum, DefId, DefIndex};
2727
use hir::map as hir_map;
2828
use hir::map::definitions::{Definitions, DefKey, DisambiguatedDefPathData};
@@ -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 describe_def(&self, def: DefId) -> Option<Def>;
185184
fn def_span(&self, sess: &Session, def: DefId) -> Span;
186185
fn stability(&self, def: DefId) -> Option<attr::Stability>;
187186
fn deprecation(&self, def: DefId) -> Option<attr::Deprecation>;
@@ -313,7 +312,6 @@ impl CrateStore for DummyCrateStore {
313312
fn crate_data_as_rc_any(&self, krate: CrateNum) -> Rc<Any>
314313
{ bug!("crate_data_as_rc_any") }
315314
// item info
316-
fn describe_def(&self, def: DefId) -> Option<Def> { bug!("describe_def") }
317315
fn def_span(&self, sess: &Session, def: DefId) -> Span { bug!("def_span") }
318316
fn stability(&self, def: DefId) -> Option<attr::Stability> { bug!("stability") }
319317
fn deprecation(&self, def: DefId) -> Option<attr::Deprecation> { bug!("deprecation") }

src/librustc/middle/stability.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
432432
// (See issue #38412)
433433
fn skip_stability_check_due_to_privacy(self, mut def_id: DefId) -> bool {
434434
// Check if `def_id` is a trait method.
435-
match self.sess.cstore.describe_def(def_id) {
435+
match self.describe_def(def_id) {
436436
Some(Def::Method(_)) |
437437
Some(Def::AssociatedTy(_)) |
438438
Some(Def::AssociatedConst(_)) => {

src/librustc/ty/maps.rs

+14-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
use dep_graph::{DepGraph, DepNode, DepTrackingMap, DepTrackingMapConfig};
1212
use hir::def_id::{CrateNum, DefId, LOCAL_CRATE};
13+
use hir::def::Def;
1314
use hir;
1415
use middle::const_val;
1516
use middle::privacy::AccessLevels;
@@ -264,6 +265,12 @@ impl<'tcx> QueryDescription for queries::symbol_name<'tcx> {
264265
}
265266
}
266267

268+
impl<'tcx> QueryDescription for queries::describe_def<'tcx> {
269+
fn describe(_: TyCtxt, _: DefId) -> String {
270+
bug!("describe_def")
271+
}
272+
}
273+
267274
macro_rules! define_maps {
268275
(<$tcx:tt>
269276
$($(#[$attr:meta])*
@@ -538,7 +545,9 @@ define_maps! { <'tcx>
538545
pub mir_shims: mir_shim_dep_node(ty::InstanceDef<'tcx>) -> &'tcx RefCell<mir::Mir<'tcx>>,
539546

540547
pub def_symbol_name: SymbolName(DefId) -> ty::SymbolName,
541-
pub symbol_name: symbol_name_dep_node(ty::Instance<'tcx>) -> ty::SymbolName
548+
pub symbol_name: symbol_name_dep_node(ty::Instance<'tcx>) -> ty::SymbolName,
549+
550+
pub describe_def: meta_data_node(DefId) -> Option<Def>
542551
}
543552

544553
fn coherent_trait_dep_node((_, def_id): (CrateNum, DefId)) -> DepNode<DefId> {
@@ -570,3 +579,7 @@ fn typeck_item_bodies_dep_node(_: CrateNum) -> DepNode<DefId> {
570579
fn const_eval_dep_node((def_id, _): (DefId, &Substs)) -> DepNode<DefId> {
571580
DepNode::ConstEval(def_id)
572581
}
582+
583+
fn meta_data_node(def_id: DefId) -> DepNode<DefId> {
584+
DepNode::MetaData(def_id)
585+
}

src/librustc/ty/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2385,7 +2385,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
23852385
/// ID of the impl that the method belongs to. Otherwise, return `None`.
23862386
pub fn impl_of_method(self, def_id: DefId) -> Option<DefId> {
23872387
let item = if def_id.krate != LOCAL_CRATE {
2388-
if let Some(Def::Method(_)) = self.sess.cstore.describe_def(def_id) {
2388+
if let Some(Def::Method(_)) = self.describe_def(def_id) {
23892389
Some(self.associated_item(def_id))
23902390
} else {
23912391
None

src/librustc_const_eval/eval.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ pub fn lookup_const_by_id<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
6868
_ => Some((def_id, substs))
6969
}
7070
} else {
71-
match tcx.sess.cstore.describe_def(def_id) {
71+
match tcx.describe_def(def_id) {
7272
Some(Def::AssociatedConst(_)) => {
7373
// As mentioned in the comments above for in-crate
7474
// constants, we only try to find the expression for a

src/librustc_metadata/cstore_impl.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use rustc::dep_graph::DepTrackingMapConfig;
1717
use rustc::middle::cstore::{CrateStore, CrateSource, LibSource, DepKind,
1818
ExternCrate, NativeLibrary, LinkMeta,
1919
LinkagePreference, LoadedMacro, EncodedMetadata};
20-
use rustc::hir::def::{self, Def};
20+
use rustc::hir::def;
2121
use rustc::middle::lang_items;
2222
use rustc::session::Session;
2323
use rustc::ty::{self, TyCtxt};
@@ -113,18 +113,14 @@ provide! { <'tcx> tcx, def_id, cdata
113113
closure_type => { cdata.closure_ty(def_id.index, tcx) }
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) }
116+
describe_def => { cdata.get_def(def_id.index) }
116117
}
117118

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

123-
fn describe_def(&self, def: DefId) -> Option<Def> {
124-
self.dep_graph.read(DepNode::MetaData(def));
125-
self.get_crate_data(def.krate).get_def(def.index)
126-
}
127-
128124
fn def_span(&self, sess: &Session, def: DefId) -> Span {
129125
self.dep_graph.read(DepNode::MetaData(def));
130126
self.get_crate_data(def.krate).get_span(def.index, sess)

0 commit comments

Comments
 (0)