diff --git a/src/librustc/hir/intravisit.rs b/src/librustc/hir/intravisit.rs index 2a351d99841..f792a24503a 100644 --- a/src/librustc/hir/intravisit.rs +++ b/src/librustc/hir/intravisit.rs @@ -57,7 +57,7 @@ pub enum FnKind<'a> { ItemFn(Name, &'a Generics, FnHeader, &'a Visibility, &'a [Attribute]), /// fn foo(&self) - Method(Name, &'a MethodSig, Option<&'a Visibility>, &'a [Attribute]), + Method(Ident, &'a MethodSig, Option<&'a Visibility>, &'a [Attribute]), /// |x, y| {} Closure(&'a [Attribute]), @@ -426,14 +426,14 @@ pub fn walk_ident<'v, V: Visitor<'v>>(visitor: &mut V, ident: Ident) { } pub fn walk_label<'v, V: Visitor<'v>>(visitor: &mut V, label: &'v Label) { - visitor.visit_name(label.span, label.name); + visitor.visit_ident(label.ident); } pub fn walk_lifetime<'v, V: Visitor<'v>>(visitor: &mut V, lifetime: &'v Lifetime) { visitor.visit_id(lifetime.id); match lifetime.name { - LifetimeName::Param(ParamName::Plain(name)) => { - visitor.visit_name(lifetime.span, name); + LifetimeName::Param(ParamName::Plain(ident)) => { + visitor.visit_ident(ident); } LifetimeName::Param(ParamName::Fresh(_)) | LifetimeName::Static | @@ -644,7 +644,7 @@ pub fn walk_path<'v, V: Visitor<'v>>(visitor: &mut V, path: &'v Path) { pub fn walk_path_segment<'v, V: Visitor<'v>>(visitor: &mut V, path_span: Span, segment: &'v PathSegment) { - visitor.visit_name(path_span, segment.name); + visitor.visit_ident(segment.ident); if let Some(ref args) = segment.args { visitor.visit_generic_args(path_span, args); } @@ -660,7 +660,7 @@ pub fn walk_generic_args<'v, V: Visitor<'v>>(visitor: &mut V, pub fn walk_assoc_type_binding<'v, V: Visitor<'v>>(visitor: &mut V, type_binding: &'v TypeBinding) { visitor.visit_id(type_binding.id); - visitor.visit_name(type_binding.span, type_binding.name); + visitor.visit_ident(type_binding.ident); visitor.visit_ty(&type_binding.ty); } @@ -689,9 +689,9 @@ pub fn walk_pat<'v, V: Visitor<'v>>(visitor: &mut V, pattern: &'v Pat) { PatKind::Ref(ref subpattern, _) => { visitor.visit_pat(subpattern) } - PatKind::Binding(_, canonical_id, ref pth1, ref optional_subpattern) => { + PatKind::Binding(_, canonical_id, ident, ref optional_subpattern) => { visitor.visit_def_mention(Def::Local(canonical_id)); - visitor.visit_name(pth1.span, pth1.node); + visitor.visit_ident(ident); walk_list!(visitor, visit_pat, optional_subpattern); } PatKind::Lit(ref expression) => visitor.visit_expr(expression), @@ -714,11 +714,11 @@ pub fn walk_foreign_item<'v, V: Visitor<'v>>(visitor: &mut V, foreign_item: &'v visitor.visit_name(foreign_item.span, foreign_item.name); match foreign_item.node { - ForeignItemFn(ref function_declaration, ref names, ref generics) => { + ForeignItemFn(ref function_declaration, ref param_names, ref generics) => { visitor.visit_generics(generics); visitor.visit_fn_decl(function_declaration); - for name in names { - visitor.visit_name(name.span, name.node); + for ¶m_name in param_names { + visitor.visit_ident(param_name); } } ForeignItemStatic(ref typ, _) => visitor.visit_ty(typ), @@ -741,7 +741,7 @@ pub fn walk_generic_param<'v, V: Visitor<'v>>(visitor: &mut V, param: &'v Generi visitor.visit_id(param.id); walk_list!(visitor, visit_attribute, ¶m.attrs); match param.name { - ParamName::Plain(name) => visitor.visit_name(param.span, name), + ParamName::Plain(ident) => visitor.visit_ident(ident), ParamName::Fresh(_) => {} } match param.kind { @@ -823,7 +823,7 @@ pub fn walk_fn<'v, V: Visitor<'v>>(visitor: &mut V, } pub fn walk_trait_item<'v, V: Visitor<'v>>(visitor: &mut V, trait_item: &'v TraitItem) { - visitor.visit_name(trait_item.span, trait_item.name); + visitor.visit_ident(trait_item.ident); walk_list!(visitor, visit_attribute, &trait_item.attrs); visitor.visit_generics(&trait_item.generics); match trait_item.node { @@ -832,15 +832,15 @@ pub fn walk_trait_item<'v, V: Visitor<'v>>(visitor: &mut V, trait_item: &'v Trai visitor.visit_ty(ty); walk_list!(visitor, visit_nested_body, default); } - TraitItemKind::Method(ref sig, TraitMethod::Required(ref names)) => { + TraitItemKind::Method(ref sig, TraitMethod::Required(ref param_names)) => { visitor.visit_id(trait_item.id); visitor.visit_fn_decl(&sig.decl); - for name in names { - visitor.visit_name(name.span, name.node); + for ¶m_name in param_names { + visitor.visit_ident(param_name); } } TraitItemKind::Method(ref sig, TraitMethod::Provided(body_id)) => { - visitor.visit_fn(FnKind::Method(trait_item.name, + visitor.visit_fn(FnKind::Method(trait_item.ident, sig, None, &trait_item.attrs), @@ -859,9 +859,9 @@ pub fn walk_trait_item<'v, V: Visitor<'v>>(visitor: &mut V, trait_item: &'v Trai pub fn walk_trait_item_ref<'v, V: Visitor<'v>>(visitor: &mut V, trait_item_ref: &'v TraitItemRef) { // NB: Deliberately force a compilation error if/when new fields are added. - let TraitItemRef { id, name, ref kind, span, ref defaultness } = *trait_item_ref; + let TraitItemRef { id, ident, ref kind, span: _, ref defaultness } = *trait_item_ref; visitor.visit_nested_trait_item(id); - visitor.visit_name(span, name); + visitor.visit_ident(ident); visitor.visit_associated_item_kind(kind); visitor.visit_defaultness(defaultness); } @@ -871,16 +871,16 @@ pub fn walk_impl_item<'v, V: Visitor<'v>>(visitor: &mut V, impl_item: &'v ImplIt let ImplItem { id: _, hir_id: _, - name, + ident, ref vis, ref defaultness, ref attrs, ref generics, ref node, - span + span: _, } = *impl_item; - visitor.visit_name(span, name); + visitor.visit_ident(ident); visitor.visit_vis(vis); visitor.visit_defaultness(defaultness); walk_list!(visitor, visit_attribute, attrs); @@ -892,7 +892,7 @@ pub fn walk_impl_item<'v, V: Visitor<'v>>(visitor: &mut V, impl_item: &'v ImplIt visitor.visit_nested_body(body); } ImplItemKind::Method(ref sig, body_id) => { - visitor.visit_fn(FnKind::Method(impl_item.name, + visitor.visit_fn(FnKind::Method(impl_item.ident, sig, Some(&impl_item.vis), &impl_item.attrs), @@ -910,9 +910,9 @@ pub fn walk_impl_item<'v, V: Visitor<'v>>(visitor: &mut V, impl_item: &'v ImplIt pub fn walk_impl_item_ref<'v, V: Visitor<'v>>(visitor: &mut V, impl_item_ref: &'v ImplItemRef) { // NB: Deliberately force a compilation error if/when new fields are added. - let ImplItemRef { id, name, ref kind, span, ref vis, ref defaultness } = *impl_item_ref; + let ImplItemRef { id, ident, ref kind, span: _, ref vis, ref defaultness } = *impl_item_ref; visitor.visit_nested_impl_item(id); - visitor.visit_name(span, name); + visitor.visit_ident(ident); visitor.visit_associated_item_kind(kind); visitor.visit_vis(vis); visitor.visit_defaultness(defaultness); diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index e14a86eb954..260ad003283 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -52,7 +52,7 @@ use middle::cstore::CrateStore; use rustc_data_structures::indexed_vec::IndexVec; use session::Session; use util::common::FN_OUTPUT_NAME; -use util::nodemap::{DefIdMap, FxHashMap, NodeMap}; +use util::nodemap::{DefIdMap, NodeMap}; use std::collections::{BTreeMap, HashSet}; use std::fmt::Debug; @@ -85,7 +85,6 @@ pub struct LoweringContext<'a> { cstore: &'a CrateStore, resolver: &'a mut Resolver, - name_map: FxHashMap, /// The items being lowered are collected here. items: BTreeMap, @@ -138,7 +137,7 @@ pub struct LoweringContext<'a> { // When `is_collectin_in_band_lifetimes` is true, each lifetime is checked // against this list to see if it is already in-scope, or if a definition // needs to be created for it. - in_scope_lifetimes: Vec, + in_scope_lifetimes: Vec, type_def_lifetime_params: DefIdMap, @@ -210,7 +209,6 @@ pub fn lower_crate( sess, cstore, resolver, - name_map: FxHashMap(), items: BTreeMap::new(), trait_items: BTreeMap::new(), impl_items: BTreeMap::new(), @@ -604,8 +602,8 @@ impl<'a> LoweringContext<'a> { self.sess.diagnostic() } - fn str_to_ident(&self, s: &'static str) -> Name { - Symbol::gensym(s) + fn str_to_ident(&self, s: &'static str) -> Ident { + Ident::with_empty_ctxt(Symbol::gensym(s)) } fn allow_internal_unstable(&self, reason: CompilerDesugaringKind, span: Span) -> Span { @@ -678,15 +676,15 @@ impl<'a> LoweringContext<'a> { // that collisions are ok here and this shouldn't // really show up for end-user. let str_name = match hir_name { - ParamName::Plain(name) => name.as_str(), - ParamName::Fresh(_) => keywords::UnderscoreLifetime.name().as_str(), + ParamName::Plain(ident) => ident.as_interned_str(), + ParamName::Fresh(_) => keywords::UnderscoreLifetime.name().as_interned_str(), }; // Add a definition for the in-band lifetime def self.resolver.definitions().create_def_with_parent( parent_id.index, def_node_id, - DefPathData::LifetimeParam(str_name.as_interned_str()), + DefPathData::LifetimeParam(str_name), DefIndexAddressSpace::High, Mark::root(), span, @@ -712,22 +710,23 @@ impl<'a> LoweringContext<'a> { /// lifetimes are enabled, then we want to push that lifetime into /// the vector of names to define later. In that case, it will get /// added to the appropriate generics. - fn maybe_collect_in_band_lifetime(&mut self, span: Span, name: Name) { + fn maybe_collect_in_band_lifetime(&mut self, ident: Ident) { if !self.is_collecting_in_band_lifetimes { return; } - if self.in_scope_lifetimes.contains(&name) { + if self.in_scope_lifetimes.contains(&ident.modern()) { return; } - let hir_name = ParamName::Plain(name); + let hir_name = ParamName::Plain(ident); - if self.lifetimes_to_define.iter().any(|(_, lt_name)| *lt_name == hir_name) { + if self.lifetimes_to_define.iter() + .any(|(_, lt_name)| lt_name.modern() == hir_name.modern()) { return; } - self.lifetimes_to_define.push((span, hir_name)); + self.lifetimes_to_define.push((ident.span, hir_name)); } /// When we have either an elided or `'_` lifetime in an impl @@ -750,7 +749,7 @@ impl<'a> LoweringContext<'a> { { let old_len = self.in_scope_lifetimes.len(); let lt_def_names = params.iter().filter_map(|param| match param.kind { - GenericParamKind::Lifetime { .. } => Some(param.ident.name), + GenericParamKind::Lifetime { .. } => Some(param.ident.modern()), _ => None, }); self.in_scope_lifetimes.extend(lt_def_names); @@ -774,7 +773,7 @@ impl<'a> LoweringContext<'a> { { let old_len = self.in_scope_lifetimes.len(); let lt_def_names = params.iter().filter_map(|param| match param.kind { - hir::GenericParamKind::Lifetime { .. } => Some(param.name.name()), + hir::GenericParamKind::Lifetime { .. } => Some(param.name.ident().modern()), _ => None, }); self.in_scope_lifetimes.extend(lt_def_names); @@ -956,20 +955,9 @@ impl<'a> LoweringContext<'a> { } } - fn lower_ident(&mut self, ident: Ident) -> Name { - let ident = ident.modern(); - if ident.span.ctxt() == SyntaxContext::empty() { - return ident.name; - } - *self.name_map - .entry(ident) - .or_insert_with(|| Symbol::from_ident(ident)) - } - fn lower_label(&mut self, label: Option