From 6234d4192a8e0cc176dd1bac6a41206a3eab95d7 Mon Sep 17 00:00:00 2001 From: varkor Date: Thu, 12 Apr 2018 21:16:26 +0100 Subject: [PATCH] Use InternedString rather than Name for RegionParameterDef This makes it consistent with TypeParameterDef. --- src/librustc/infer/mod.rs | 3 ++- src/librustc/ty/mod.rs | 2 +- src/librustc/ty/sty.rs | 4 ++-- src/librustc/util/ppaux.rs | 17 ++++++++--------- src/librustc_driver/test.rs | 2 +- src/librustc_typeck/astconv.rs | 2 +- src/librustc_typeck/collect.rs | 4 ++-- src/librustdoc/clean/auto_trait.rs | 8 ++++---- 8 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/librustc/infer/mod.rs b/src/librustc/infer/mod.rs index 032a5c59d2dca..84bf9cc84e737 100644 --- a/src/librustc/infer/mod.rs +++ b/src/librustc/infer/mod.rs @@ -35,6 +35,7 @@ use std::fmt; use syntax::ast; use errors::DiagnosticBuilder; use syntax_pos::{self, Span}; +use syntax_pos::symbol::InternedString; use util::nodemap::FxHashMap; use arena::DroplessArena; @@ -343,7 +344,7 @@ pub enum RegionVariableOrigin { Coercion(Span), // Region variables created as the values for early-bound regions - EarlyBoundRegion(Span, ast::Name), + EarlyBoundRegion(Span, InternedString), // Region variables created for bound regions // in a function or method that is called diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs index 33b59eda7ce2c..77106fd61adf6 100644 --- a/src/librustc/ty/mod.rs +++ b/src/librustc/ty/mod.rs @@ -728,7 +728,7 @@ pub struct TypeParameterDef { #[derive(Copy, Clone, RustcEncodable, RustcDecodable)] pub struct RegionParameterDef { - pub name: Name, + pub name: InternedString, pub def_id: DefId, pub index: u32, diff --git a/src/librustc/ty/sty.rs b/src/librustc/ty/sty.rs index 7a9174cbfaf73..d68393956efd1 100644 --- a/src/librustc/ty/sty.rs +++ b/src/librustc/ty/sty.rs @@ -58,7 +58,7 @@ pub enum BoundRegion { /// /// The def-id is needed to distinguish free regions in /// the event of shadowing. - BrNamed(DefId, Name), + BrNamed(DefId, InternedString), /// Fresh bound identifiers created during GLB computations. BrFresh(u32), @@ -1058,7 +1058,7 @@ impl<'tcx> serialize::UseSpecializedDecodable for Region<'tcx> {} pub struct EarlyBoundRegion { pub def_id: DefId, pub index: u32, - pub name: Name, + pub name: InternedString, } #[derive(Clone, Copy, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)] diff --git a/src/librustc/util/ppaux.rs b/src/librustc/util/ppaux.rs index d27cda4040e56..dd478967b185a 100644 --- a/src/librustc/util/ppaux.rs +++ b/src/librustc/util/ppaux.rs @@ -30,7 +30,7 @@ use std::usize; use rustc_data_structures::indexed_vec::Idx; use syntax::abi::Abi; use syntax::ast::CRATE_NODE_ID; -use syntax::symbol::Symbol; +use syntax::symbol::{Symbol, InternedString}; use hir; macro_rules! gen_display_debug_body { @@ -130,7 +130,7 @@ macro_rules! print { } -struct LateBoundRegionNameCollector(FxHashSet); +struct LateBoundRegionNameCollector(FxHashSet); impl<'tcx> ty::fold::TypeVisitor<'tcx> for LateBoundRegionNameCollector { fn visit_region(&mut self, r: ty::Region<'tcx>) -> bool { match *r { @@ -148,7 +148,7 @@ pub struct PrintContext { is_debug: bool, is_verbose: bool, identify_regions: bool, - used_region_names: Option>, + used_region_names: Option>, region_index: usize, binder_depth: usize, } @@ -440,12 +440,12 @@ impl PrintContext { lifted: Option>) -> fmt::Result where T: Print, U: Print + TypeFoldable<'tcx>, F: fmt::Write { - fn name_by_region_index(index: usize) -> Symbol { + fn name_by_region_index(index: usize) -> InternedString { match index { 0 => Symbol::intern("'r"), 1 => Symbol::intern("'s"), i => Symbol::intern(&format!("'t{}", i-2)), - } + }.as_str() } // Replace any anonymous late-bound regions with named @@ -493,8 +493,7 @@ impl PrintContext { } }; let _ = write!(f, "{}", name); - ty::BrNamed(tcx.hir.local_def_id(CRATE_NODE_ID), - name) + ty::BrNamed(tcx.hir.local_def_id(CRATE_NODE_ID), name) } }; tcx.mk_region(ty::ReLateBound(ty::DebruijnIndex::new(1), br)) @@ -510,7 +509,7 @@ impl PrintContext { result } - fn is_name_used(&self, name: &Symbol) -> bool { + fn is_name_used(&self, name: &InternedString) -> bool { match self.used_region_names { Some(ref names) => names.contains(name), None => false, @@ -697,7 +696,7 @@ define_print! { BrAnon(n) => write!(f, "BrAnon({:?})", n), BrFresh(n) => write!(f, "BrFresh({:?})", n), BrNamed(did, name) => { - write!(f, "BrNamed({:?}:{:?}, {:?})", + write!(f, "BrNamed({:?}:{:?}, {})", did.krate, did.index, name) } BrEnv => write!(f, "BrEnv"), diff --git a/src/librustc_driver/test.rs b/src/librustc_driver/test.rs index 971855ee2d007..5aae895ccc4d5 100644 --- a/src/librustc_driver/test.rs +++ b/src/librustc_driver/test.rs @@ -307,7 +307,7 @@ impl<'a, 'gcx, 'tcx> Env<'a, 'gcx, 'tcx> { } pub fn re_early_bound(&self, index: u32, name: &'static str) -> ty::Region<'tcx> { - let name = Symbol::intern(name); + let name = Symbol::intern(name).as_str(); self.infcx.tcx.mk_region(ty::ReEarlyBound(ty::EarlyBoundRegion { def_id: self.infcx.tcx.hir.local_def_id(ast::CRATE_NODE_ID), index, diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index c4ea543ab36b6..36debf677da2b 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -100,7 +100,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o { { let tcx = self.tcx(); let lifetime_name = |def_id| { - tcx.hir.name(tcx.hir.as_local_node_id(def_id).unwrap()) + tcx.hir.name(tcx.hir.as_local_node_id(def_id).unwrap()).as_str() }; let hir_id = tcx.hir.node_to_hir_id(lifetime.id); diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index a4f820d1fdcf9..4f797c8c861ea 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -885,7 +885,7 @@ fn generics_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, let early_lifetimes = early_bound_lifetimes_from_generics(tcx, ast_generics); let regions = early_lifetimes.enumerate().map(|(i, l)| { ty::RegionParameterDef { - name: l.lifetime.name.name(), + name: l.lifetime.name.name().as_str(), index: own_start + i as u32, def_id: tcx.hir.local_def_id(l.lifetime.id), pure_wrt_drop: l.pure_wrt_drop, @@ -1422,7 +1422,7 @@ fn explicit_predicates_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, let region = tcx.mk_region(ty::ReEarlyBound(ty::EarlyBoundRegion { def_id: tcx.hir.local_def_id(param.lifetime.id), index, - name: param.lifetime.name.name(), + name: param.lifetime.name.name().as_str(), })); index += 1; diff --git a/src/librustdoc/clean/auto_trait.rs b/src/librustdoc/clean/auto_trait.rs index 888148352c70a..52d5dbe3f0589 100644 --- a/src/librustdoc/clean/auto_trait.rs +++ b/src/librustdoc/clean/auto_trait.rs @@ -224,7 +224,7 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> { let name = if p.name == "" { hir::LifetimeName::Static } else { - hir::LifetimeName::Name(p.name) + hir::LifetimeName::Name(Symbol::intern(&p.name)) }; hir::Lifetime { @@ -407,7 +407,7 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> { let names_map: FxHashMap = generics .regions .iter() - .map(|l| (l.name.as_str().to_string(), l.clean(self.cx))) + .map(|l| (l.name.to_string(), l.clean(self.cx))) .collect(); let body_ids: FxHashSet<_> = infcx @@ -728,7 +728,7 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> { fn region_name(&self, region: Region) -> Option { match region { - &ty::ReEarlyBound(r) => Some(r.name.as_str().to_string()), + &ty::ReEarlyBound(r) => Some(r.name.to_string()), _ => None, } } @@ -1005,7 +1005,7 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> { // We only care about late bound regions, as we need to add them // to the 'for<>' section &ty::ReLateBound(_, ty::BoundRegion::BrNamed(_, name)) => { - Some(GenericParam::Lifetime(Lifetime(name.as_str().to_string()))) + Some(GenericParam::Lifetime(Lifetime(name.to_string()))) } &ty::ReVar(_) | &ty::ReEarlyBound(_) => None, _ => panic!("Unexpected region type {:?}", r),