]> git.lizzy.rs Git - rust.git/commitdiff
rustc: Store InternedString in `DefPathData`
authorAlex Crichton <alex@alexcrichton.com>
Fri, 1 Sep 2017 16:24:02 +0000 (09:24 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Tue, 5 Sep 2017 14:47:27 +0000 (07:47 -0700)
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.

23 files changed:
src/librustc/hir/lowering.rs
src/librustc/hir/map/def_collector.rs
src/librustc/hir/map/definitions.rs
src/librustc/traits/error_reporting.rs
src/librustc/traits/on_unimplemented.rs
src/librustc/ty/item_path.rs
src/librustc/ty/maps.rs
src/librustc/ty/mod.rs
src/librustc_const_eval/eval.rs
src/librustc_driver/test.rs
src/librustc_metadata/cstore_impl.rs
src/librustc_metadata/decoder.rs
src/librustc_mir/build/expr/into.rs
src/librustc_mir/shim.rs
src/librustc_mir/transform/qualify_consts.rs
src/librustc_resolve/build_reduced_graph.rs
src/librustc_trans/back/symbol_names.rs
src/librustc_trans/debuginfo/metadata.rs
src/librustc_trans/debuginfo/type_names.rs
src/librustc_trans/intrinsic.rs
src/librustc_trans/mir/block.rs
src/librustc_trans/mir/constant.rs
src/librustdoc/clean/mod.rs

index d657b9bbe67e3b03d94f2281c784c1c70fce7236..db86c4f93ee5269a6739f23e041e2539d3df9b33 100644 (file)
@@ -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,
index d348a5db0517041e5c588b012cf6bbda89cf0e4f..af027e321c6a1da4e4f235e607d0898466eee3e0 100644 (file)
@@ -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);
     }
 
index b371366bc5d5589b5de54be67b052c7583dc7f2a..7bd2e5eceaec6faa8c974236e83323e1a26cc288 100644 (file)
@@ -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<Symbol> {
+    pub fn get_opt_name(&self) -> Option<InternedString> {
         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,
                     }
                 };
index 498dc0cf2559d1167b2d21c3eb6f69c503a68bd2..cfbd4ba055e3c3827e27fa68319ba19f2a194a33 100644 (file)
@@ -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)));
             }
index 7dd3fc70b1e3fbf18852932d0c58fe5426eb4df5..94f6efcad4adc7efdee2cd0ed6e47edf74f229f4 100644 (file)
@@ -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| {
index 75cf792d8ab40b59191d72af5130e460a570d844..d9d311b14a36ec78f36c0238ff3f6b08cc94410a 100644 (file)
@@ -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<T>(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::<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 @@ pub fn try_push_visible_item_path<T>(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<T>(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("<unnamed>")));
+                Symbol::intern("<unnamed>").as_str()));
             match visible_parent_map.get(&cur_def) {
                 Some(&def) => cur_def = def,
                 None => return false,
index 65d70bb9fd040212f36e5c028469409c9af423b7..29e5e4e3431346e674466b57374a749c709ffd10 100644 (file)
@@ -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};
index d4c352f00a7756748688a6da8c4cc0629303e1b7..ef0d844be957f0569062d667770e96d540eded3c 100644 (file)
@@ -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.
index 27a25ff73d15ee1b6ba5da74fa174cffadc4ec78..ea6e1d4cddcca8b5d8dd7caab5213e7fd25130ca 100644 (file)
@@ -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(),
index 567c8b7e3f73df1b8d6d5968e4d8445818d06c93..de710942ca189595855fb2f205fd6555fc1ab7fe 100644 (file)
@@ -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<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| {
index dbb188e923a0250b8a9daf03bb8c0ab2f7f3b800..61881bc033bea6fbc1fe69fd52ff612b3501f4bf 100644 (file)
@@ -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(),
index 2523c97cfab84ee7d0b40e15ecac8565d45e3053..324bab369dc7d1dc38eb463133c84eeb5cb31f97 100644 (file)
@@ -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<F>(&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<F>(&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<ast::Name> {
         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<DefId> {
             .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)),
index 80a126dc42569c2d0563116237137fe2ddfcda59..ec06e474980a63478a68a681e3a2f30dab256ad7 100644 (file)
@@ -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
                         }
index 023bec57b3f361fc1168596ad0b337095c159785..ec545443bcd9040629bbbea6b2521e3b827ec57b 100644 (file)
@@ -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" {
index 3b36ff8ce57c430dfc9e8d6f8adceca104b83da3..ded97275468b9170d0ae2cb45a025ac285f5d804 100644 (file)
@@ -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") => {
index e3589ad58cfa37c83dd2a1ef2611a8afa653b6c8..35e7522db0184435b6a2aedc1ca408d765add146 100644 (file)
@@ -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);
index 10b66fb1991087a351150bcc8ec921a8cd7ce349..abeb2568cbe1eea17f1645ace755b12fa35d7055 100644 (file)
@@ -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
index bcc6aca6149bd05b7fac3046f848585160038c4e..8bd835ac5d114564f1f53b3c572e9a27ed653e08 100644 (file)
@@ -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)
     }
 }
 
index 5dd1c15fd2d6ed88aec2783fd009fcdc512d207f..6eda86575193371c4baf04f53212eb1a8dc74450 100644 (file)
@@ -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));
         }
     }
 
index 53e2419125573d404af566c09d59b083ef408c41..8f968a8a6c60977779d028fcc726d2d16741b4a9 100644 (file)
@@ -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);
 
index bba3b1fa5baee102f3873310c99c19f09a53e76e..0f42a244a1ff906ef4e6a543c66eb5b6ef612f6a 100644 (file)
@@ -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[..]);
index e8b1430b4b07f21d35e0e9a859d0b5274006b1be..1109f34a1482e16a834a5f3ad1b6aaedc98ecfd5 100644 (file)
@@ -365,7 +365,7 @@ fn trans(&mut self) -> Result<Const<'tcx>, 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)));
index 9d61bc2fa5aab341e22669f8b95e3c11cb75d549..e8927e28d753b9b001a2f36a49e0ae01e51d3cc1 100644 (file)
@@ -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 @@ 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,