let parent_def = self.parent_def.unwrap();
let def_id = {
let defs = self.resolver.definitions();
- let def_path_data = DefPathData::Binding(name);
+ let def_path_data = DefPathData::Binding(name.as_str());
let def_index = defs.create_def_with_parent(parent_def,
node_id,
def_path_data,
DefPathData::Impl,
ItemKind::Enum(..) | ItemKind::Struct(..) | ItemKind::Union(..) | ItemKind::Trait(..) |
ItemKind::ExternCrate(..) | ItemKind::ForeignMod(..) | ItemKind::Ty(..) =>
- DefPathData::TypeNs(i.ident.name),
+ DefPathData::TypeNs(i.ident.name.as_str()),
ItemKind::Mod(..) if i.ident == keywords::Invalid.ident() => {
return visit::walk_item(self, i);
}
- ItemKind::Mod(..) => DefPathData::Module(i.ident.name),
+ ItemKind::Mod(..) => DefPathData::Module(i.ident.name.as_str()),
ItemKind::Static(..) | ItemKind::Const(..) | ItemKind::Fn(..) =>
- DefPathData::ValueNs(i.ident.name),
- ItemKind::MacroDef(..) => DefPathData::MacroDef(i.ident.name),
+ DefPathData::ValueNs(i.ident.name.as_str()),
+ ItemKind::MacroDef(..) => DefPathData::MacroDef(i.ident.name.as_str()),
ItemKind::Mac(..) => return self.visit_macro_invoc(i.id, false),
ItemKind::GlobalAsm(..) => DefPathData::Misc,
ItemKind::Use(ref view_path) => {
for v in &enum_definition.variants {
let variant_def_index =
this.create_def(v.node.data.id(),
- DefPathData::EnumVariant(v.node.name.name),
+ DefPathData::EnumVariant(v.node.name.name.as_str()),
REGULAR_SPACE);
this.with_parent(variant_def_index, |this| {
for (index, field) in v.node.data.fields().iter().enumerate() {
let name = field.ident.map(|ident| ident.name)
.unwrap_or_else(|| Symbol::intern(&index.to_string()));
- this.create_def(field.id, DefPathData::Field(name), REGULAR_SPACE);
+ this.create_def(field.id,
+ DefPathData::Field(name.as_str()),
+ REGULAR_SPACE);
}
if let Some(ref expr) = v.node.disr_expr {
for (index, field) in struct_def.fields().iter().enumerate() {
let name = field.ident.map(|ident| ident.name)
.unwrap_or_else(|| Symbol::intern(&index.to_string()));
- this.create_def(field.id, DefPathData::Field(name), REGULAR_SPACE);
+ this.create_def(field.id, DefPathData::Field(name.as_str()), REGULAR_SPACE);
}
}
_ => {}
fn visit_foreign_item(&mut self, foreign_item: &'a ForeignItem) {
let def = self.create_def(foreign_item.id,
- DefPathData::ValueNs(foreign_item.ident.name),
+ DefPathData::ValueNs(foreign_item.ident.name.as_str()),
REGULAR_SPACE);
self.with_parent(def, |this| {
fn visit_generics(&mut self, generics: &'a Generics) {
for ty_param in generics.ty_params.iter() {
self.create_def(ty_param.id,
- DefPathData::TypeParam(ty_param.ident.name),
+ DefPathData::TypeParam(ty_param.ident.name.as_str()),
REGULAR_SPACE);
}
fn visit_trait_item(&mut self, ti: &'a TraitItem) {
let def_data = match ti.node {
TraitItemKind::Method(..) | TraitItemKind::Const(..) =>
- DefPathData::ValueNs(ti.ident.name),
- TraitItemKind::Type(..) => DefPathData::TypeNs(ti.ident.name),
+ DefPathData::ValueNs(ti.ident.name.as_str()),
+ TraitItemKind::Type(..) => DefPathData::TypeNs(ti.ident.name.as_str()),
TraitItemKind::Macro(..) => return self.visit_macro_invoc(ti.id, false),
};
fn visit_impl_item(&mut self, ii: &'a ImplItem) {
let def_data = match ii.node {
ImplItemKind::Method(..) | ImplItemKind::Const(..) =>
- DefPathData::ValueNs(ii.ident.name),
- ImplItemKind::Type(..) => DefPathData::TypeNs(ii.ident.name),
+ DefPathData::ValueNs(ii.ident.name.as_str()),
+ ImplItemKind::Type(..) => DefPathData::TypeNs(ii.ident.name.as_str()),
ImplItemKind::Macro(..) => return self.visit_macro_invoc(ii.id, false),
};
PatKind::Mac(..) => return self.visit_macro_invoc(pat.id, false),
PatKind::Ident(_, id, _) => {
let def = self.create_def(pat.id,
- DefPathData::Binding(id.node.name),
+ DefPathData::Binding(id.node.name.as_str()),
REGULAR_SPACE);
self.parent_def = Some(def);
}
fn visit_lifetime_def(&mut self, def: &'a LifetimeDef) {
self.create_def(def.lifetime.id,
- DefPathData::LifetimeDef(def.lifetime.ident.name),
+ DefPathData::LifetimeDef(def.lifetime.ident.name.as_str()),
REGULAR_SPACE);
}
#[inline(always)]
pub fn def_path_hash(&self, index: DefIndex) -> DefPathHash {
- self.def_path_hashes[index.address_space().index()]
- [index.as_array_index()]
+ let ret = self.def_path_hashes[index.address_space().index()]
+ [index.as_array_index()];
+ debug!("def_path_hash({:?}) = {:?}", index, ret);
+ return ret
}
pub fn add_def_path_hashes_to(&self,
DefPathData::Binding(name) |
DefPathData::Field(name) |
DefPathData::GlobalMetaData(name) => {
- (*name.as_str()).hash(&mut hasher);
+ name.hash(&mut hasher);
}
DefPathData::Impl |
/// An impl
Impl,
/// Something in the type NS
- TypeNs(Symbol),
+ TypeNs(InternedString),
/// Something in the value NS
- ValueNs(Symbol),
+ ValueNs(InternedString),
/// A module declaration
- Module(Symbol),
+ Module(InternedString),
/// A macro rule
- MacroDef(Symbol),
+ MacroDef(InternedString),
/// A closure expression
ClosureExpr,
// Subportions of items
/// A type parameter (generic parameter)
- TypeParam(Symbol),
+ TypeParam(InternedString),
/// A lifetime definition
- LifetimeDef(Symbol),
+ LifetimeDef(InternedString),
/// A variant of a enum
- EnumVariant(Symbol),
+ EnumVariant(InternedString),
/// A struct field
- Field(Symbol),
+ Field(InternedString),
/// Implicit ctor for a tuple-like struct
StructCtor,
/// Initializer for a const
Initializer,
/// Pattern binding
- Binding(Symbol),
+ Binding(InternedString),
/// An `impl Trait` type node.
ImplTrait,
/// A `typeof` type node.
/// GlobalMetaData identifies a piece of crate metadata that is global to
/// a whole crate (as opposed to just one item). GlobalMetaData components
/// are only supposed to show up right below the crate root.
- GlobalMetaData(Symbol)
+ GlobalMetaData(InternedString)
}
#[derive(Copy, Clone, Hash, PartialEq, Eq, PartialOrd, Ord, Debug,
}
impl DefPathData {
- pub fn get_opt_name(&self) -> Option<Symbol> {
+ pub fn get_opt_name(&self) -> Option<InternedString> {
use self::DefPathData::*;
match *self {
TypeNs(name) |
Binding(name) |
Field(name) |
GlobalMetaData(name) => {
- return name.as_str();
+ return name
}
// note that this does not show up in user printouts
definitions.create_def_with_parent(
CRATE_DEF_INDEX,
ast::DUMMY_NODE_ID,
- DefPathData::GlobalMetaData(instance.name()),
+ DefPathData::GlobalMetaData(instance.name().as_str()),
GLOBAL_MD_ADDRESS_SPACE,
Mark::root()
);
let def_key = DefKey {
parent: Some(CRATE_DEF_INDEX),
disambiguated_data: DisambiguatedDefPathData {
- data: DefPathData::GlobalMetaData(self.name()),
+ data: DefPathData::GlobalMetaData(self.name().as_str()),
disambiguator: 0,
}
};
//
// Currently I'm leaving it for what I need for `try`.
if self.tcx.trait_of_item(item) == Some(trait_ref.def_id) {
- method = self.tcx.item_name(item).as_str();
+ method = self.tcx.item_name(item);
flags.push(("from_method", None));
flags.push(("from_method", Some(&*method)));
}
span: Span)
-> Result<(), ErrorReported>
{
- let name = tcx.item_name(trait_def_id).as_str();
+ let name = tcx.item_name(trait_def_id);
let generics = tcx.generics_of(trait_def_id);
let parser = Parser::new(&self.0);
let types = &generics.types;
trait_ref: ty::TraitRef<'tcx>)
-> String
{
- let name = tcx.item_name(trait_ref.def_id).as_str();
+ let name = tcx.item_name(trait_ref.def_id);
let trait_str = tcx.item_path_str(trait_ref.def_id);
let generics = tcx.generics_of(trait_ref.def_id);
let generic_map = generics.types.iter().map(|param| {
use ty::{self, Ty, TyCtxt};
use syntax::ast;
use syntax::symbol::Symbol;
+use syntax::symbol::InternedString;
use std::cell::Cell;
{
let visible_parent_map = self.visible_parent_map(LOCAL_CRATE);
- let (mut cur_def, mut cur_path) = (external_def_id, Vec::<ast::Name>::new());
+ let (mut cur_def, mut cur_path) = (external_def_id, Vec::<InternedString>::new());
loop {
// If `cur_def` is a direct or injected extern crate, push the path to the crate
// followed by the path to the item within the crate and return.
match *self.extern_crate(cur_def) {
Some(ref extern_crate) if extern_crate.direct => {
self.push_item_path(buffer, extern_crate.def_id);
- cur_path.iter().rev().map(|segment| buffer.push(&segment.as_str())).count();
+ cur_path.iter().rev().map(|segment| buffer.push(&segment)).count();
return true;
}
None => {
buffer.push(&self.crate_name(cur_def.krate).as_str());
- cur_path.iter().rev().map(|segment| buffer.push(&segment.as_str())).count();
+ cur_path.iter().rev().map(|segment| buffer.push(&segment)).count();
return true;
}
_ => {},
cur_path.push(self.sess.cstore.def_key(cur_def)
.disambiguated_data.data.get_opt_name().unwrap_or_else(||
- Symbol::intern("<unnamed>")));
+ Symbol::intern("<unnamed>").as_str()));
match visible_parent_map.get(&cur_def) {
Some(&def) => cur_def = def,
None => return false,
use middle::cstore::{NativeLibraryKind, DepKind, CrateSource};
use middle::privacy::AccessLevels;
use middle::region;
-use middle::region::RegionMaps;
use middle::resolve_lifetime::{Region, ObjectLifetimeDefault};
use middle::stability::{self, DeprecationEntry};
use middle::lang_items::{LanguageItems, LangItem};
}
}
- pub fn item_name(self, id: DefId) -> ast::Name {
+ pub fn item_name(self, id: DefId) -> InternedString {
if let Some(id) = self.hir.as_local_node_id(id) {
- self.hir.name(id)
+ self.hir.name(id).as_str()
} else if id.index == CRATE_DEF_INDEX {
- self.original_crate_name(id.krate)
+ self.original_crate_name(id.krate).as_str()
} else {
let def_key = self.sess.cstore.def_key(id);
// The name of a StructCtor is that of its struct parent.
ConstEvalErr { span: e.span, kind: LayoutError(err) }
})
};
- match &tcx.item_name(def_id).as_str()[..] {
+ match &tcx.item_name(def_id)[..] {
"size_of" => {
let size = layout_of(substs.type_at(0))?.size(tcx);
return Ok(Integral(Usize(ConstUsize::new(size.bytes(),
use rustc::middle::free_region::FreeRegionMap;
use rustc::middle::region;
use rustc::middle::resolve_lifetime;
-use rustc::middle::stability;
use rustc::ty::subst::{Kind, Subst};
use rustc::traits::{ObligationCause, Reveal};
use rustc::ty::{self, Ty, TyCtxt, TypeFoldable};
// run just enough stuff to build a tcx:
let named_region_map = resolve_lifetime::krate(&sess, &hir_map);
- let index = stability::Index::new(&sess);
TyCtxt::create_and_enter(&sess,
ty::maps::Providers::default(),
ty::maps::Providers::default(),
resolutions,
named_region_map.unwrap(),
hir_map,
- index,
"test_crate",
|tcx| {
tcx.infer_ctxt().enter(|infcx| {
use syntax::symbol::Symbol;
use syntax_pos::{Span, NO_EXPANSION};
use rustc_data_structures::indexed_set::IdxSetBuf;
-use rustc::hir::svh::Svh;
use rustc::hir;
macro_rules! provide {
.insert(local_span, (name.to_string(), data.get_span(id.index, sess)));
LoadedMacro::MacroDef(ast::Item {
- ident: ast::Ident::with_empty_ctxt(name),
+ ident: ast::Ident::from_str(&name),
id: ast::DUMMY_NODE_ID,
span: local_span,
attrs: attrs.iter().cloned().collect(),
use syntax::attr;
use syntax::ast::{self, Ident};
use syntax::codemap;
+use syntax::symbol::{InternedString, Symbol};
use syntax::ext::base::MacroKind;
use syntax_pos::{self, Span, BytePos, Pos, DUMMY_SP, NO_EXPANSION};
}
}
- pub fn item_name(&self, item_index: DefIndex) -> ast::Name {
+ pub fn item_name(&self, item_index: DefIndex) -> InternedString {
self.def_key(item_index)
.disambiguated_data
.data
ty::VariantDef {
did: self.local_def_id(data.struct_ctor.unwrap_or(index)),
- name: self.item_name(index),
+ name: Symbol::intern(&self.item_name(index)),
fields: item.children.decode(self).map(|index| {
let f = self.entry(index);
ty::FieldDef {
did: self.local_def_id(index),
- name: self.item_name(index),
+ name: Symbol::intern(&self.item_name(index)),
vis: f.visibility.decode(self)
}
}).collect(),
if let Some(def) = self.get_def(child_index) {
callback(def::Export {
def,
- ident: Ident::with_empty_ctxt(self.item_name(child_index)),
+ ident: Ident::from_str(&self.item_name(child_index)),
span: self.entry(child_index).span.decode((self, sess)),
});
}
let span = child.span.decode((self, sess));
if let (Some(def), Some(name)) =
(self.get_def(child_index), def_key.disambiguated_data.data.get_opt_name()) {
- let ident = Ident::with_empty_ctxt(name);
+ let ident = Ident::from_str(&name);
callback(def::Export { def: def, ident: ident, span: span });
// For non-reexport structs and variants add their constructors to children.
// Reexport lists automatically contain constructors when necessary.
};
ty::AssociatedItem {
- name,
+ name: Symbol::intern(&name),
kind,
vis: item.visibility.decode(self),
defaultness: container.defaultness(),
self.entry(id)
.children
.decode(self)
- .map(|index| self.item_name(index))
+ .map(|index| Symbol::intern(&self.item_name(index)))
.collect()
}
.collect()
}
- pub fn get_macro(&self, id: DefIndex) -> (ast::Name, MacroDef) {
+ pub fn get_macro(&self, id: DefIndex) -> (InternedString, MacroDef) {
let entry = self.entry(id);
match entry.kind {
EntryKind::MacroDef(macro_def) => (self.item_name(id), macro_def.decode(self)),
let f = ty.fn_sig(this.hir.tcx());
if f.abi() == Abi::RustIntrinsic ||
f.abi() == Abi::PlatformIntrinsic {
- Some(this.hir.tcx().item_name(def_id).as_str())
+ Some(this.hir.tcx().item_name(def_id))
} else {
None
}
build_drop_shim(tcx, def_id, ty)
}
ty::InstanceDef::CloneShim(def_id, ty) => {
- let name = tcx.item_name(def_id).as_str();
+ let name = tcx.item_name(def_id);
if name == "clone" {
build_clone_shim(tcx, def_id, ty)
} else if name == "clone_from" {
Abi::RustIntrinsic |
Abi::PlatformIntrinsic => {
assert!(!self.tcx.is_const_fn(def_id));
- match &self.tcx.item_name(def_id).as_str()[..] {
+ match &self.tcx.item_name(def_id)[..] {
"size_of" | "min_align_of" => is_const_fn = true,
name if name.starts_with("simd_shuffle") => {
use syntax::ext::tt::macro_rules;
use syntax::parse::token;
use syntax::symbol::keywords;
+use syntax::symbol::Symbol;
use syntax::visit::{self, Visitor};
use syntax_pos::{Span, DUMMY_SP};
}
let (name, parent) = if def_id.index == CRATE_DEF_INDEX {
- (self.session.cstore.crate_name_untracked(def_id.krate), None)
+ (self.session.cstore.crate_name_untracked(def_id.krate).as_str(), None)
} else {
let def_key = self.session.cstore.def_key(def_id);
(def_key.disambiguated_data.data.get_opt_name().unwrap(),
Some(self.get_module(DefId { index: def_key.parent.unwrap(), ..def_id })))
};
- let kind = ModuleKind::Def(Def::Mod(def_id), name);
+ let kind = ModuleKind::Def(Def::Mod(def_id), Symbol::intern(&name));
let module =
self.arenas.alloc_module(ModuleData::new(parent, kind, def_id, Mark::root(), DUMMY_SP));
self.extern_module_map.insert((def_id, macros_only), module);
return name.to_string();
}
// Don't mangle foreign items.
- return tcx.item_name(def_id).as_str().to_string();
+ return tcx.item_name(def_id).to_string();
}
if let Some(name) = attr::find_export_name_attr(tcx.sess.diagnostic(), &attrs) {
if attr::contains_name(&attrs, "no_mangle") {
// Don't mangle
- return tcx.item_name(def_id).as_str().to_string();
+ return tcx.item_name(def_id).to_string();
}
// We want to compute the "type" of this item. Unfortunately, some
fn get_enum_discriminant_name(cx: &CrateContext,
def_id: DefId)
-> InternedString {
- cx.tcx().item_name(def_id).as_str()
+ cx.tcx().item_name(def_id)
}
}
output.push_str(&path_element.data.as_interned_str());
}
} else {
- output.push_str(&cx.tcx().item_name(def_id).as_str());
+ output.push_str(&cx.tcx().item_name(def_id));
}
}
let sig = tcx.erase_late_bound_regions_and_normalize(&sig);
let arg_tys = sig.inputs();
let ret_ty = sig.output();
- let name = &*tcx.item_name(def_id).as_str();
+ let name = &*tcx.item_name(def_id);
let llret_ty = type_of::type_of(ccx, ret_ty);
// Handle intrinsics old trans wants Expr's for, ourselves.
let intrinsic = match def {
Some(ty::InstanceDef::Intrinsic(def_id))
- => Some(bcx.tcx().item_name(def_id).as_str()),
+ => Some(bcx.tcx().item_name(def_id)),
_ => None
};
let intrinsic = intrinsic.as_ref().map(|s| &s[..]);
}
if let Some((ref dest, target)) = *destination {
let result = if fn_ty.fn_sig(tcx).abi() == Abi::RustIntrinsic {
- match &tcx.item_name(def_id).as_str()[..] {
+ match &tcx.item_name(def_id)[..] {
"size_of" => {
let llval = C_uint(self.ccx,
self.ccx.size_of(substs.type_at(0)));
fn maybe_sized(cx: &DocContext) -> TyParamBound {
let did = cx.tcx.require_lang_item(lang_items::SizedTraitLangItem);
let empty = cx.tcx.intern_substs(&[]);
- let path = external_path(cx, &cx.tcx.item_name(did).as_str(),
+ let path = external_path(cx, &cx.tcx.item_name(did),
Some(did), false, vec![], empty);
inline::record_extern_fqn(cx, did, TypeKind::Trait);
TraitBound(PolyTrait {
impl<'tcx> Clean<TyParamBound> for ty::TraitRef<'tcx> {
fn clean(&self, cx: &DocContext) -> TyParamBound {
inline::record_extern_fqn(cx, self.def_id, TypeKind::Trait);
- let path = external_path(cx, &cx.tcx.item_name(self.def_id).as_str(),
+ let path = external_path(cx, &cx.tcx.item_name(self.def_id),
Some(self.def_id), true, vec![], self.substs);
debug!("ty::TraitRef\n subst: {:?}\n", self.substs);
AdtKind::Enum => TypeKind::Enum,
};
inline::record_extern_fqn(cx, did, kind);
- let path = external_path(cx, &cx.tcx.item_name(did).as_str(),
+ let path = external_path(cx, &cx.tcx.item_name(did),
None, false, vec![], substs);
ResolvedPath {
path,
reg.clean(cx).map(|b| typarams.push(RegionBound(b)));
for did in obj.auto_traits() {
let empty = cx.tcx.intern_substs(&[]);
- let path = external_path(cx, &cx.tcx.item_name(did).as_str(),
+ let path = external_path(cx, &cx.tcx.item_name(did),
Some(did), false, vec![], empty);
inline::record_extern_fqn(cx, did, TypeKind::Trait);
let bound = TraitBound(PolyTrait {
});
}
- let path = external_path(cx, &cx.tcx.item_name(did).as_str(), Some(did),
+ let path = external_path(cx, &cx.tcx.item_name(did), Some(did),
false, bindings, principal.0.substs);
ResolvedPath {
path,