use std::fmt::Write;
use std::hash::{Hash, Hasher, SipHasher};
use syntax::{ast, visit};
-use syntax::parse::token::InternedString;
+use syntax::parse::token::{self, InternedString};
use ty::TyCtxt;
use util::nodemap::NodeMap;
}
impl DefPathData {
+ pub fn get_opt_name(&self) -> Option<ast::Name> {
+ use self::DefPathData::*;
+ match *self {
+ TypeNs(ref name) |
+ ValueNs(ref name) |
+ Module(ref name) |
+ MacroDef(ref name) |
+ TypeParam(ref name) |
+ LifetimeDef(ref name) |
+ EnumVariant(ref name) |
+ Binding(ref name) |
+ Field(ref name) => Some(token::intern(name)),
+
+ Impl |
+ CrateRoot |
+ InlinedRoot(_) |
+ Misc |
+ ClosureExpr |
+ StructCtor |
+ Initializer |
+ ImplTrait => None
+ }
+ }
+
pub fn as_interned_str(&self) -> InternedString {
use self::DefPathData::*;
match *self {
fn item_type<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId)
-> Ty<'tcx>;
fn visible_parent_map<'a>(&'a self) -> ::std::cell::RefMut<'a, DefIdMap<DefId>>;
- fn opt_item_name(&self, def: DefId) -> Option<ast::Name>;
fn item_predicates<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId)
-> ty::GenericPredicates<'tcx>;
fn item_super_predicates<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId)
fn visible_parent_map<'a>(&'a self) -> ::std::cell::RefMut<'a, DefIdMap<DefId>> {
bug!("visible_parent_map")
}
- fn opt_item_name(&self, def: DefId) -> Option<ast::Name> { bug!("opt_item_name") }
fn item_predicates<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId)
-> ty::GenericPredicates<'tcx> { bug!("item_predicates") }
fn item_super_predicates<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId)
pub trait MacroLoader {
fn load_crate(&mut self, extern_crate: &ast::Item, allows_macros: bool) -> Vec<LoadedMacro>;
-}
\ No newline at end of file
+}
}
}
- cur_path.push(self.sess.cstore.opt_item_name(cur_def).unwrap_or_else(||
+ cur_path.push(self.sess.cstore.def_key(cur_def)
+ .disambiguated_data.data.get_opt_name().unwrap_or_else(||
token::intern("<unnamed>")));
match visible_parent_map.get(&cur_def) {
Some(&def) => cur_def = def,
use hir::map as ast_map;
use middle;
use hir::def::{Def, PathResolution, ExportMap};
-use hir::def_id::{CrateNum, DefId, LOCAL_CRATE};
+use hir::def_id::{CrateNum, DefId, CRATE_DEF_INDEX, LOCAL_CRATE};
use middle::lang_items::{FnTraitLangItem, FnMutTraitLangItem, FnOnceTraitLangItem};
use middle::region::{CodeExtent, ROOT_CODE_EXTENT};
use traits;
use std::vec::IntoIter;
use syntax::ast::{self, Name, NodeId};
use syntax::attr;
-use syntax::parse::token::InternedString;
+use syntax::parse::token::{self, InternedString};
use syntax_pos::{DUMMY_SP, Span};
use rustc_const_math::ConstInt;
pub fn item_name(self, id: DefId) -> ast::Name {
if let Some(id) = self.map.as_local_node_id(id) {
self.map.name(id)
+ } else if id.index == CRATE_DEF_INDEX {
+ token::intern(&self.sess.cstore.original_crate_name(id.krate))
} else {
- self.sess.cstore.opt_item_name(id).unwrap_or_else(|| {
- bug!("item_name: no name for {:?}", self.def_path(id));
- })
+ let def_key = self.sess.cstore.def_key(id);
+ // The name of a StructCtor is that of its struct parent.
+ if let ast_map::DefPathData::StructCtor = def_key.disambiguated_data.data {
+ self.item_name(DefId {
+ krate: id.krate,
+ index: def_key.parent.unwrap()
+ })
+ } else {
+ def_key.disambiguated_data.data.get_opt_name().unwrap_or_else(|| {
+ bug!("item_name: no name for {:?}", self.def_path(id));
+ })
+ }
}
}
self.get_crate_data(did.krate).get_fn_arg_names(did.index)
}
- fn opt_item_name(&self, def: DefId) -> Option<ast::Name> {
- self.dep_graph.read(DepNode::MetaData(def));
- let cdata = self.get_crate_data(def.krate);
- if def.index == CRATE_DEF_INDEX {
- Some(token::intern(&cdata.name()))
- } else {
- cdata.maybe_get_item_name(def.index)
- }
- }
-
fn inherent_implementations_for_type(&self, def_id: DefId) -> Vec<DefId>
{
self.dep_graph.read(DepNode::MetaData(def_id));
use syntax::attr;
use syntax::ast::{self, NodeId};
use syntax::codemap;
-use syntax::parse::token;
use syntax_pos::{self, Span, BytePos, Pos};
pub struct DecodeContext<'a, 'tcx: 'a> {
}
}
-fn def_key_name(def_key: &hir_map::DefKey) -> Option<ast::Name> {
- match def_key.disambiguated_data.data {
- DefPathData::TypeNs(ref name) |
- DefPathData::ValueNs(ref name) |
- DefPathData::Module(ref name) |
- DefPathData::MacroDef(ref name) |
- DefPathData::TypeParam(ref name) |
- DefPathData::LifetimeDef(ref name) |
- DefPathData::EnumVariant(ref name) |
- DefPathData::Field(ref name) |
- DefPathData::Binding(ref name) => {
- Some(token::intern(name))
- }
-
- DefPathData::InlinedRoot(_) => bug!("unexpected DefPathData"),
-
- DefPathData::CrateRoot |
- DefPathData::Misc |
- DefPathData::Impl |
- DefPathData::ClosureExpr |
- DefPathData::StructCtor |
- DefPathData::Initializer |
- DefPathData::ImplTrait => None
- }
-}
-
impl<'a, 'tcx> CrateMetadata {
fn maybe_entry(&self, item_id: DefIndex) -> Option<Lazy<Entry<'tcx>>> {
self.root.index.lookup(self.blob.raw_bytes(), item_id)
}
fn item_name(&self, item: &Entry<'tcx>) -> ast::Name {
- def_key_name(&item.def_key.decode(self)).expect("no name in item_name")
+ item.def_key.decode(self).disambiguated_data.data.get_opt_name()
+ .expect("no name in item_name")
}
pub fn get_def(&self, index: DefIndex) -> Option<Def> {
_ => {}
}
- if let Some(name) = def_key_name(&child.def_key.decode(self)) {
+ let def_key = child.def_key.decode(self);
+ if let Some(name) = def_key.disambiguated_data.data.get_opt_name() {
callback(def::Export {
def_id: self.local_def_id(child_index),
name: name
}
}
- pub fn maybe_get_item_name(&self, id: DefIndex) -> Option<ast::Name> {
- def_key_name(&self.entry(id).def_key.decode(self))
- }
-
pub fn maybe_get_item_ast(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, id: DefIndex)
-> Option<&'tcx InlinedItem> {
debug!("Looking up item: {:?}", id);
let parent_and_name = || {
let def_key = item.def_key.decode(self);
(self.local_def_id(def_key.parent.unwrap()),
- def_key_name(&def_key).unwrap())
+ def_key.disambiguated_data.data.get_opt_name().unwrap())
};
Some(match item.kind {
let trait_item_def_ids = self.session.cstore.impl_or_trait_items(def_id);
for &trait_item_def in &trait_item_def_ids {
let trait_item_name =
- self.session.cstore.opt_item_name(trait_item_def)
+ self.session.cstore.def_key(trait_item_def)
+ .disambiguated_data.data.get_opt_name()
.expect("opt_item_name returned None for trait");
debug!("(building reduced graph for external crate) ... adding trait item \