rustc: Store InternedString in `DefPathData`
Previously a `Symbol` was stored there, but this ended up causing hash collisions in situations that otherwise shouldn't have a hash collision. Only the symbol's string value was hashed, but it was possible for distinct symbols to have the same string value, fooling various calcuations into thinking that these paths *didn't* need disambiguating data when in fact they did! By storing `InternedString` instead we're hopefully triggering all the exising logic to disambiguate paths with same-name `Symbol` but actually distinct locations.
This commit is contained in:
parent
9a231961d5
commit
0cdc58a1bc
|
@ -2863,7 +2863,7 @@ impl<'a> LoweringContext<'a> {
|
|||
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,
|
||||
|
|
|
@ -104,14 +104,14 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
|
|||
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) => {
|
||||
|
@ -139,13 +139,15 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
|
|||
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 {
|
||||
|
@ -165,7 +167,7 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
|
|||
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);
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
|
@ -176,7 +178,7 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
|
|||
|
||||
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| {
|
||||
|
@ -187,7 +189,7 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
|
|||
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);
|
||||
}
|
||||
|
||||
|
@ -197,8 +199,8 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
|
|||
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),
|
||||
};
|
||||
|
||||
|
@ -215,8 +217,8 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
|
|||
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),
|
||||
};
|
||||
|
||||
|
@ -237,7 +239,7 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
|
|||
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);
|
||||
}
|
||||
|
@ -282,7 +284,7 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
|
|||
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
|
@ -80,8 +80,10 @@ impl DefPathTable {
|
|||
|
||||
#[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,
|
||||
|
@ -213,7 +215,7 @@ impl DefKey {
|
|||
DefPathData::Binding(name) |
|
||||
DefPathData::Field(name) |
|
||||
DefPathData::GlobalMetaData(name) => {
|
||||
(*name.as_str()).hash(&mut hasher);
|
||||
name.hash(&mut hasher);
|
||||
}
|
||||
|
||||
DefPathData::Impl |
|
||||
|
@ -347,31 +349,31 @@ pub enum DefPathData {
|
|||
/// 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.
|
||||
|
@ -380,7 +382,7 @@ pub enum DefPathData {
|
|||
/// 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,
|
||||
|
@ -601,7 +603,7 @@ impl Definitions {
|
|||
}
|
||||
|
||||
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) |
|
||||
|
@ -639,7 +641,7 @@ impl DefPathData {
|
|||
Binding(name) |
|
||||
Field(name) |
|
||||
GlobalMetaData(name) => {
|
||||
return name.as_str();
|
||||
return name
|
||||
}
|
||||
|
||||
// note that this does not show up in user printouts
|
||||
|
@ -684,7 +686,7 @@ macro_rules! define_global_metadata_kind {
|
|||
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()
|
||||
);
|
||||
|
@ -698,7 +700,7 @@ macro_rules! define_global_metadata_kind {
|
|||
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,
|
||||
}
|
||||
};
|
||||
|
|
|
@ -348,7 +348,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
|||
//
|
||||
// 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)));
|
||||
}
|
||||
|
|
|
@ -227,7 +227,7 @@ impl<'a, 'gcx, 'tcx> OnUnimplementedFormatString {
|
|||
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;
|
||||
|
@ -272,7 +272,7 @@ impl<'a, 'gcx, 'tcx> OnUnimplementedFormatString {
|
|||
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| {
|
||||
|
|
|
@ -13,6 +13,7 @@ use hir::def_id::{CrateNum, DefId, CRATE_DEF_INDEX, LOCAL_CRATE};
|
|||
use ty::{self, Ty, TyCtxt};
|
||||
use syntax::ast;
|
||||
use syntax::symbol::Symbol;
|
||||
use syntax::symbol::InternedString;
|
||||
|
||||
use std::cell::Cell;
|
||||
|
||||
|
@ -130,7 +131,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
|||
{
|
||||
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.
|
||||
|
@ -138,12 +139,12 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
|||
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;
|
||||
}
|
||||
_ => {},
|
||||
|
@ -152,7 +153,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
|||
|
||||
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,
|
||||
|
|
|
@ -20,7 +20,6 @@ use middle::cstore::{ExternCrate, LinkagePreference, NativeLibrary};
|
|||
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};
|
||||
|
|
|
@ -2206,11 +2206,11 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
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.
|
||||
|
|
|
@ -327,7 +327,7 @@ fn eval_const_expr_partial<'a, 'tcx>(cx: &ConstContext<'a, 'tcx>,
|
|||
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(),
|
||||
|
|
|
@ -18,7 +18,6 @@ use rustc_trans;
|
|||
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};
|
||||
|
@ -140,7 +139,6 @@ fn test_env<F>(source_string: &str,
|
|||
|
||||
// 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(),
|
||||
|
@ -150,7 +148,6 @@ fn test_env<F>(source_string: &str,
|
|||
resolutions,
|
||||
named_region_map.unwrap(),
|
||||
hir_map,
|
||||
index,
|
||||
"test_crate",
|
||||
|tcx| {
|
||||
tcx.infer_ctxt().enter(|infcx| {
|
||||
|
|
|
@ -40,7 +40,6 @@ use syntax::parse::filemap_to_stream;
|
|||
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 {
|
||||
|
@ -469,7 +468,7 @@ impl CrateStore for cstore::CStore {
|
|||
.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(),
|
||||
|
|
|
@ -41,6 +41,7 @@ use rustc_serialize::{Decodable, Decoder, SpecializedDecoder, opaque};
|
|||
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};
|
||||
|
||||
|
@ -473,7 +474,7 @@ impl<'a, 'tcx> CrateMetadata {
|
|||
}
|
||||
}
|
||||
|
||||
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
|
||||
|
@ -520,12 +521,12 @@ impl<'a, 'tcx> CrateMetadata {
|
|||
|
||||
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(),
|
||||
|
@ -705,7 +706,7 @@ impl<'a, 'tcx> CrateMetadata {
|
|||
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)),
|
||||
});
|
||||
}
|
||||
|
@ -722,7 +723,7 @@ impl<'a, 'tcx> CrateMetadata {
|
|||
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.
|
||||
|
@ -836,7 +837,7 @@ impl<'a, 'tcx> CrateMetadata {
|
|||
};
|
||||
|
||||
ty::AssociatedItem {
|
||||
name,
|
||||
name: Symbol::intern(&name),
|
||||
kind,
|
||||
vis: item.visibility.decode(self),
|
||||
defaultness: container.defaultness(),
|
||||
|
@ -906,7 +907,7 @@ impl<'a, 'tcx> CrateMetadata {
|
|||
self.entry(id)
|
||||
.children
|
||||
.decode(self)
|
||||
.map(|index| self.item_name(index))
|
||||
.map(|index| Symbol::intern(&self.item_name(index)))
|
||||
.collect()
|
||||
}
|
||||
|
||||
|
@ -1038,7 +1039,7 @@ impl<'a, 'tcx> CrateMetadata {
|
|||
.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)),
|
||||
|
|
|
@ -209,7 +209,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
|
|||
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
|
||||
}
|
||||
|
|
|
@ -100,7 +100,7 @@ fn make_shim<'a, 'tcx>(tcx: ty::TyCtxt<'a, 'tcx, 'tcx>,
|
|||
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" {
|
||||
|
|
|
@ -824,7 +824,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> {
|
|||
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") => {
|
||||
|
|
|
@ -42,6 +42,7 @@ use syntax::ext::hygiene::Mark;
|
|||
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};
|
||||
|
@ -522,14 +523,14 @@ impl<'a> Resolver<'a> {
|
|||
}
|
||||
|
||||
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);
|
||||
|
|
|
@ -242,7 +242,7 @@ fn compute_symbol_name<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, instance: Instance
|
|||
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) {
|
||||
|
@ -252,7 +252,7 @@ fn compute_symbol_name<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, instance: Instance
|
|||
|
||||
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
|
||||
|
|
|
@ -1612,7 +1612,7 @@ fn prepare_enum_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
|
|||
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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -189,7 +189,7 @@ pub fn push_debuginfo_type_name<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
|
|||
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));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -104,7 +104,7 @@ pub fn trans_intrinsic_call<'a, 'tcx>(bcx: &Builder<'a, 'tcx>,
|
|||
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);
|
||||
|
||||
|
|
|
@ -445,7 +445,7 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> {
|
|||
// 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[..]);
|
||||
|
|
|
@ -365,7 +365,7 @@ impl<'a, 'tcx> MirConstContext<'a, 'tcx> {
|
|||
}
|
||||
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)));
|
||||
|
|
|
@ -672,7 +672,7 @@ impl TyParamBound {
|
|||
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 {
|
||||
|
@ -763,7 +763,7 @@ fn external_path(cx: &DocContext, name: &str, trait_did: Option<DefId>, has_self
|
|||
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);
|
||||
|
@ -1915,7 +1915,7 @@ impl<'tcx> Clean<Type> for ty::Ty<'tcx> {
|
|||
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,
|
||||
|
@ -1933,7 +1933,7 @@ impl<'tcx> Clean<Type> for ty::Ty<'tcx> {
|
|||
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 {
|
||||
|
@ -1956,7 +1956,7 @@ impl<'tcx> Clean<Type> for ty::Ty<'tcx> {
|
|||
});
|
||||
}
|
||||
|
||||
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,
|
||||
|
|
Loading…
Reference in New Issue