From 0cdc58a1bc6ea5ce9ba11c21bfd6d5b85b3efc87 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Fri, 1 Sep 2017 09:24:02 -0700 Subject: [PATCH] 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. --- src/librustc/hir/lowering.rs | 2 +- src/librustc/hir/map/def_collector.rs | 32 +++++++++-------- src/librustc/hir/map/definitions.rs | 36 +++++++++++--------- src/librustc/traits/error_reporting.rs | 2 +- src/librustc/traits/on_unimplemented.rs | 4 +-- src/librustc/ty/item_path.rs | 9 ++--- src/librustc/ty/maps.rs | 1 - src/librustc/ty/mod.rs | 6 ++-- src/librustc_const_eval/eval.rs | 2 +- src/librustc_driver/test.rs | 3 -- src/librustc_metadata/cstore_impl.rs | 3 +- src/librustc_metadata/decoder.rs | 17 ++++----- src/librustc_mir/build/expr/into.rs | 2 +- src/librustc_mir/shim.rs | 2 +- src/librustc_mir/transform/qualify_consts.rs | 2 +- src/librustc_resolve/build_reduced_graph.rs | 5 +-- src/librustc_trans/back/symbol_names.rs | 4 +-- src/librustc_trans/debuginfo/metadata.rs | 2 +- src/librustc_trans/debuginfo/type_names.rs | 2 +- src/librustc_trans/intrinsic.rs | 2 +- src/librustc_trans/mir/block.rs | 2 +- src/librustc_trans/mir/constant.rs | 2 +- src/librustdoc/clean/mod.rs | 10 +++--- 23 files changed, 77 insertions(+), 75 deletions(-) diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index d657b9bbe67..db86c4f93ee 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -2863,7 +2863,7 @@ fn pat_ident_binding_mode(&mut self, span: Span, name: Name, bm: hir::BindingAnn 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, diff --git a/src/librustc/hir/map/def_collector.rs b/src/librustc/hir/map/def_collector.rs index d348a5db051..af027e321c6 100644 --- a/src/librustc/hir/map/def_collector.rs +++ b/src/librustc/hir/map/def_collector.rs @@ -104,14 +104,14 @@ fn visit_item(&mut self, i: &'a Item) { 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 @@ fn visit_item(&mut self, i: &'a Item) { 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 @@ fn visit_item(&mut self, i: &'a Item) { 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 @@ fn visit_item(&mut self, i: &'a Item) { 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 @@ fn visit_foreign_item(&mut self, foreign_item: &'a ForeignItem) { 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 @@ fn visit_generics(&mut self, generics: &'a Generics) { 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 @@ fn visit_trait_item(&mut self, ti: &'a TraitItem) { 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 @@ fn visit_pat(&mut self, pat: &'a Pat) { 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 @@ fn visit_ty(&mut self, ty: &'a Ty) { 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); } diff --git a/src/librustc/hir/map/definitions.rs b/src/librustc/hir/map/definitions.rs index b371366bc5d..7bd2e5eceae 100644 --- a/src/librustc/hir/map/definitions.rs +++ b/src/librustc/hir/map/definitions.rs @@ -80,8 +80,10 @@ pub fn def_key(&self, index: DefIndex) -> DefKey { #[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 @@ fn compute_stable_hash(&self, parent_hash: DefPathHash) -> DefPathHash { 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 @@ pub fn add_macro_def_scope(&mut self, mark: Mark, scope: DefId) { } impl DefPathData { - pub fn get_opt_name(&self) -> Option { + pub fn get_opt_name(&self) -> Option { use self::DefPathData::*; match *self { TypeNs(name) | @@ -639,7 +641,7 @@ pub fn as_interned_str(&self) -> InternedString { 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 @@ fn allocate_def_indices(definitions: &mut Definitions) { 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 @@ pub fn def_index(&self, def_path_table: &DefPathTable) -> DefIndex { 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, } }; diff --git a/src/librustc/traits/error_reporting.rs b/src/librustc/traits/error_reporting.rs index 498dc0cf255..cfbd4ba055e 100644 --- a/src/librustc/traits/error_reporting.rs +++ b/src/librustc/traits/error_reporting.rs @@ -348,7 +348,7 @@ fn on_unimplemented_note( // // 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))); } diff --git a/src/librustc/traits/on_unimplemented.rs b/src/librustc/traits/on_unimplemented.rs index 7dd3fc70b1e..94f6efcad4a 100644 --- a/src/librustc/traits/on_unimplemented.rs +++ b/src/librustc/traits/on_unimplemented.rs @@ -227,7 +227,7 @@ fn verify(&self, 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 @@ pub fn format(&self, 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| { diff --git a/src/librustc/ty/item_path.rs b/src/librustc/ty/item_path.rs index 75cf792d8ab..d9d311b14a3 100644 --- a/src/librustc/ty/item_path.rs +++ b/src/librustc/ty/item_path.rs @@ -13,6 +13,7 @@ use ty::{self, Ty, TyCtxt}; use syntax::ast; use syntax::symbol::Symbol; +use syntax::symbol::InternedString; use std::cell::Cell; @@ -130,7 +131,7 @@ pub fn try_push_visible_item_path(self, buffer: &mut T, external_def_id: DefI { let visible_parent_map = self.visible_parent_map(LOCAL_CRATE); - let (mut cur_def, mut cur_path) = (external_def_id, Vec::::new()); + let (mut cur_def, mut cur_path) = (external_def_id, Vec::::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 @@ pub fn try_push_visible_item_path(self, buffer: &mut T, external_def_id: DefI 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 @@ pub fn try_push_visible_item_path(self, buffer: &mut T, external_def_id: DefI cur_path.push(self.sess.cstore.def_key(cur_def) .disambiguated_data.data.get_opt_name().unwrap_or_else(|| - Symbol::intern(""))); + Symbol::intern("").as_str())); match visible_parent_map.get(&cur_def) { Some(&def) => cur_def = def, None => return false, diff --git a/src/librustc/ty/maps.rs b/src/librustc/ty/maps.rs index 65d70bb9fd0..29e5e4e3431 100644 --- a/src/librustc/ty/maps.rs +++ b/src/librustc/ty/maps.rs @@ -20,7 +20,6 @@ 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}; diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs index d4c352f00a7..ef0d844be95 100644 --- a/src/librustc/ty/mod.rs +++ b/src/librustc/ty/mod.rs @@ -2206,11 +2206,11 @@ pub fn def_path_hash(self, def_id: DefId) -> hir_map::DefPathHash { } } - 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. diff --git a/src/librustc_const_eval/eval.rs b/src/librustc_const_eval/eval.rs index 27a25ff73d1..ea6e1d4cddc 100644 --- a/src/librustc_const_eval/eval.rs +++ b/src/librustc_const_eval/eval.rs @@ -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(), diff --git a/src/librustc_driver/test.rs b/src/librustc_driver/test.rs index 567c8b7e3f7..de710942ca1 100644 --- a/src/librustc_driver/test.rs +++ b/src/librustc_driver/test.rs @@ -18,7 +18,6 @@ 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(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(source_string: &str, resolutions, named_region_map.unwrap(), hir_map, - index, "test_crate", |tcx| { tcx.infer_ctxt().enter(|infcx| { diff --git a/src/librustc_metadata/cstore_impl.rs b/src/librustc_metadata/cstore_impl.rs index dbb188e923a..61881bc033b 100644 --- a/src/librustc_metadata/cstore_impl.rs +++ b/src/librustc_metadata/cstore_impl.rs @@ -40,7 +40,6 @@ 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 @@ fn load_macro_untracked(&self, id: DefId, sess: &Session) -> LoadedMacro { .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(), diff --git a/src/librustc_metadata/decoder.rs b/src/librustc_metadata/decoder.rs index 2523c97cfab..324bab369dc 100644 --- a/src/librustc_metadata/decoder.rs +++ b/src/librustc_metadata/decoder.rs @@ -41,6 +41,7 @@ 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 @@ fn local_def_id(&self, index: DefIndex) -> DefId { } } - 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 @@ fn get_variant(&self, item: &Entry, index: DefIndex) -> ty::VariantDef { 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 @@ pub fn each_child_of_item(&self, id: DefIndex, mut callback: F, sess: &Sessio 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 @@ pub fn each_child_of_item(&self, id: DefIndex, mut callback: F, sess: &Sessio 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 @@ pub fn get_associated_item(&self, id: DefIndex) -> ty::AssociatedItem { }; ty::AssociatedItem { - name, + name: Symbol::intern(&name), kind, vis: item.visibility.decode(self), defaultness: container.defaultness(), @@ -906,7 +907,7 @@ pub fn get_struct_field_names(&self, id: DefIndex) -> Vec { 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 @@ pub fn get_exported_symbols(&self, dep_graph: &DepGraph) -> Vec { .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)), diff --git a/src/librustc_mir/build/expr/into.rs b/src/librustc_mir/build/expr/into.rs index 80a126dc425..ec06e474980 100644 --- a/src/librustc_mir/build/expr/into.rs +++ b/src/librustc_mir/build/expr/into.rs @@ -209,7 +209,7 @@ pub fn into_expr(&mut 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 } diff --git a/src/librustc_mir/shim.rs b/src/librustc_mir/shim.rs index 023bec57b3f..ec545443bcd 100644 --- a/src/librustc_mir/shim.rs +++ b/src/librustc_mir/shim.rs @@ -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" { diff --git a/src/librustc_mir/transform/qualify_consts.rs b/src/librustc_mir/transform/qualify_consts.rs index 3b36ff8ce57..ded97275468 100644 --- a/src/librustc_mir/transform/qualify_consts.rs +++ b/src/librustc_mir/transform/qualify_consts.rs @@ -824,7 +824,7 @@ fn visit_terminator_kind(&mut self, 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") => { diff --git a/src/librustc_resolve/build_reduced_graph.rs b/src/librustc_resolve/build_reduced_graph.rs index e3589ad58cf..35e7522db01 100644 --- a/src/librustc_resolve/build_reduced_graph.rs +++ b/src/librustc_resolve/build_reduced_graph.rs @@ -42,6 +42,7 @@ 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 @@ pub fn get_module(&mut self, def_id: DefId) -> Module<'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); diff --git a/src/librustc_trans/back/symbol_names.rs b/src/librustc_trans/back/symbol_names.rs index 10b66fb1991..abeb2568cbe 100644 --- a/src/librustc_trans/back/symbol_names.rs +++ b/src/librustc_trans/back/symbol_names.rs @@ -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 diff --git a/src/librustc_trans/debuginfo/metadata.rs b/src/librustc_trans/debuginfo/metadata.rs index bcc6aca6149..8bd835ac5d1 100644 --- a/src/librustc_trans/debuginfo/metadata.rs +++ b/src/librustc_trans/debuginfo/metadata.rs @@ -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) } } diff --git a/src/librustc_trans/debuginfo/type_names.rs b/src/librustc_trans/debuginfo/type_names.rs index 5dd1c15fd2d..6eda8657519 100644 --- a/src/librustc_trans/debuginfo/type_names.rs +++ b/src/librustc_trans/debuginfo/type_names.rs @@ -189,7 +189,7 @@ fn push_item_name(cx: &CrateContext, 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)); } } diff --git a/src/librustc_trans/intrinsic.rs b/src/librustc_trans/intrinsic.rs index 53e24191255..8f968a8a6c6 100644 --- a/src/librustc_trans/intrinsic.rs +++ b/src/librustc_trans/intrinsic.rs @@ -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); diff --git a/src/librustc_trans/mir/block.rs b/src/librustc_trans/mir/block.rs index bba3b1fa5ba..0f42a244a1f 100644 --- a/src/librustc_trans/mir/block.rs +++ b/src/librustc_trans/mir/block.rs @@ -445,7 +445,7 @@ fn trans_terminator(&mut self, // 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[..]); diff --git a/src/librustc_trans/mir/constant.rs b/src/librustc_trans/mir/constant.rs index e8b1430b4b0..1109f34a148 100644 --- a/src/librustc_trans/mir/constant.rs +++ b/src/librustc_trans/mir/constant.rs @@ -365,7 +365,7 @@ fn trans(&mut self) -> Result, ConstEvalErr<'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))); diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 9d61bc2fa5a..e8927e28d75 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -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, has_self impl<'tcx> Clean 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 @@ fn clean(&self, cx: &DocContext) -> Type { 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 @@ fn clean(&self, cx: &DocContext) -> Type { 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 @@ fn clean(&self, cx: &DocContext) -> Type { }); } - 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, -- 2.44.0