Skip to content

Commit 70944c2

Browse files
No need to have tcx::opt_def_path() now that we store all DefPaths
1 parent 72f95aa commit 70944c2

File tree

5 files changed

+13
-49
lines changed

5 files changed

+13
-49
lines changed

src/librustc/hir/def_id.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,7 @@ impl fmt::Debug for DefId {
120120

121121
ty::tls::with_opt(|opt_tcx| {
122122
if let Some(tcx) = opt_tcx {
123-
if let Some(def_path) = tcx.opt_def_path(*self) {
124-
write!(f, " => {}", def_path.to_string(tcx))?;
125-
}
123+
write!(f, " => {}", tcx.def_path(*self).to_string(tcx))?;
126124
}
127125
Ok(())
128126
})?;

src/librustc/middle/cstore.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ pub trait CrateStore<'tcx> {
341341
path_data: &[DisambiguatedDefPathData])
342342
-> Option<DefId>;
343343
fn def_key(&self, def: DefId) -> DefKey;
344-
fn relative_def_path(&self, def: DefId) -> Option<hir_map::DefPath>;
344+
fn def_path(&self, def: DefId) -> hir_map::DefPath;
345345
fn struct_field_names(&self, def: DefId) -> Vec<ast::Name>;
346346
fn item_children(&self, did: DefId) -> Vec<def::Export>;
347347
fn load_macro(&self, did: DefId, sess: &Session) -> LoadedMacro;
@@ -510,7 +510,7 @@ impl<'tcx> CrateStore<'tcx> for DummyCrateStore {
510510
}
511511

512512
fn def_key(&self, def: DefId) -> DefKey { bug!("def_key") }
513-
fn relative_def_path(&self, def: DefId) -> Option<hir_map::DefPath> {
513+
fn def_path(&self, def: DefId) -> hir_map::DefPath {
514514
bug!("relative_def_path")
515515
}
516516
fn struct_field_names(&self, def: DefId) -> Vec<ast::Name> { bug!("struct_field_names") }

src/librustc/ty/mod.rs

Lines changed: 4 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2241,40 +2241,13 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
22412241
/// Convert a `DefId` into its fully expanded `DefPath` (every
22422242
/// `DefId` is really just an interned def-path).
22432243
///
2244-
/// Note that if `id` is not local to this crate -- or is
2245-
/// inlined into this crate -- the result will be a non-local
2246-
/// `DefPath`.
2247-
///
2248-
/// This function is only safe to use when you are sure that the
2249-
/// full def-path is accessible. Examples that are known to be
2250-
/// safe are local def-ids or items; see `opt_def_path` for more
2251-
/// details.
2244+
/// Note that if `id` is not local to this crate, the result will
2245+
// be a non-local `DefPath`.
22522246
pub fn def_path(self, id: DefId) -> ast_map::DefPath {
2253-
self.opt_def_path(id).unwrap_or_else(|| {
2254-
bug!("could not load def-path for {:?}", id)
2255-
})
2256-
}
2257-
2258-
/// Convert a `DefId` into its fully expanded `DefPath` (every
2259-
/// `DefId` is really just an interned def-path).
2260-
///
2261-
/// When going across crates, we do not save the full info for
2262-
/// every cross-crate def-id, and hence we may not always be able
2263-
/// to create a def-path. Therefore, this returns
2264-
/// `Option<DefPath>` to cover that possibility. It will always
2265-
/// return `Some` for local def-ids, however, as well as for
2266-
/// items. The problems arise with "minor" def-ids like those
2267-
/// associated with a pattern, `impl Trait`, or other internal
2268-
/// detail to a fn.
2269-
///
2270-
/// Note that if `id` is not local to this crate -- or is
2271-
/// inlined into this crate -- the result will be a non-local
2272-
/// `DefPath`.
2273-
pub fn opt_def_path(self, id: DefId) -> Option<ast_map::DefPath> {
22742247
if id.is_local() {
2275-
Some(self.map.def_path(id))
2248+
self.map.def_path(id)
22762249
} else {
2277-
self.sess.cstore.relative_def_path(id)
2250+
self.sess.cstore.def_path(id)
22782251
}
22792252
}
22802253

src/librustc_metadata/cstore_impl.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ impl<'tcx> CrateStore<'tcx> for cstore::CStore {
358358
self.get_crate_data(def.krate).def_key(def.index)
359359
}
360360

361-
fn relative_def_path(&self, def: DefId) -> Option<DefPath> {
361+
fn def_path(&self, def: DefId) -> DefPath {
362362
// See `Note` above in `def_key()` for why this read is
363363
// commented out:
364364
//

src/librustc_metadata/decoder.rs

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ use astencode::decode_inlined_item;
1414
use cstore::{self, CrateMetadata, MetadataBlob, NativeLibrary};
1515
use schema::*;
1616

17-
use rustc::hir::map as hir_map;
18-
use rustc::hir::map::{DefKey, DefPathData};
17+
use rustc::hir::map::{DefKey, DefPath, DefPathData};
1918
use rustc::hir;
2019
use rustc::hir::intravisit::IdRange;
2120

@@ -567,7 +566,7 @@ impl<'a, 'tcx> CrateMetadata {
567566
ty::TraitDef::new(self.local_def_id(item_id),
568567
data.unsafety,
569568
data.paren_sugar,
570-
self.def_path(item_id).unwrap().deterministic_hash(tcx))
569+
self.def_path(item_id).deterministic_hash(tcx))
571570
}
572571

573572
fn get_variant(&self,
@@ -1128,16 +1127,10 @@ impl<'a, 'tcx> CrateMetadata {
11281127
self.def_path_table.def_key(index)
11291128
}
11301129

1131-
// Returns the path leading to the thing with this `id`. Note that
1132-
// some def-ids don't wind up in the metadata, so `def_path` sometimes
1133-
// returns `None`
1134-
pub fn def_path(&self, id: DefIndex) -> Option<hir_map::DefPath> {
1130+
// Returns the path leading to the thing with this `id`.
1131+
pub fn def_path(&self, id: DefIndex) -> DefPath {
11351132
debug!("def_path(id={:?})", id);
1136-
if self.is_proc_macro(id) || self.maybe_entry(id).is_some() {
1137-
Some(hir_map::DefPath::make(self.cnum, id, |parent| self.def_key(parent)))
1138-
} else {
1139-
None
1140-
}
1133+
DefPath::make(self.cnum, id, |parent| self.def_path_table.def_key(parent))
11411134
}
11421135

11431136
/// Imports the codemap from an external crate into the codemap of the crate

0 commit comments

Comments
 (0)