diff --git a/compiler/rustc_borrowck/src/renumber.rs b/compiler/rustc_borrowck/src/renumber.rs index 0fbf01dbe4455..f37a7cce3b3ec 100644 --- a/compiler/rustc_borrowck/src/renumber.rs +++ b/compiler/rustc_borrowck/src/renumber.rs @@ -69,12 +69,10 @@ impl RegionCtxt { /// Used to determine the representative of a component in the strongly connected /// constraint graph pub(crate) fn preference_value(self) -> usize { - let _anon = Symbol::intern("anon"); - match self { RegionCtxt::Unknown => 1, RegionCtxt::Existential(None) => 2, - RegionCtxt::Existential(Some(_anon)) | RegionCtxt::Free(_anon) => 2, + RegionCtxt::Existential(Some(_)) | RegionCtxt::Free(_) => 2, RegionCtxt::Location(_) => 3, RegionCtxt::TyContext(_) => 4, _ => 5, diff --git a/compiler/rustc_borrowck/src/type_check/mod.rs b/compiler/rustc_borrowck/src/type_check/mod.rs index 5658b956ec092..6d8305b7d471b 100644 --- a/compiler/rustc_borrowck/src/type_check/mod.rs +++ b/compiler/rustc_borrowck/src/type_check/mod.rs @@ -35,6 +35,7 @@ use rustc_middle::ty::{ OpaqueHiddenType, OpaqueTypeKey, RegionVid, Ty, TyCtxt, UserType, UserTypeAnnotationIndex, }; use rustc_span::def_id::CRATE_DEF_ID; +use rustc_span::symbol::sym; use rustc_span::{Span, DUMMY_SP}; use rustc_target::abi::{FieldIdx, FIRST_VARIANT}; use rustc_trait_selection::traits::query::type_op::custom::scrape_region_constraints; @@ -1338,18 +1339,13 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { }; let (sig, map) = tcx.replace_late_bound_regions(sig, |br| { use crate::renumber::{BoundRegionInfo, RegionCtxt}; - use rustc_span::Symbol; let region_ctxt_fn = || { let reg_info = match br.kind { ty::BoundRegionKind::BrAnon(Some(span)) => BoundRegionInfo::Span(span), - ty::BoundRegionKind::BrAnon(..) => { - BoundRegionInfo::Name(Symbol::intern("anon")) - } + ty::BoundRegionKind::BrAnon(..) => BoundRegionInfo::Name(sym::anon), ty::BoundRegionKind::BrNamed(_, name) => BoundRegionInfo::Name(name), - ty::BoundRegionKind::BrEnv => { - BoundRegionInfo::Name(Symbol::intern("env")) - } + ty::BoundRegionKind::BrEnv => BoundRegionInfo::Name(sym::env), }; RegionCtxt::LateBound(reg_info) diff --git a/compiler/rustc_borrowck/src/type_check/relate_tys.rs b/compiler/rustc_borrowck/src/type_check/relate_tys.rs index 83429f2ddef36..6b64e65518f5b 100644 --- a/compiler/rustc_borrowck/src/type_check/relate_tys.rs +++ b/compiler/rustc_borrowck/src/type_check/relate_tys.rs @@ -4,6 +4,7 @@ use rustc_infer::traits::PredicateObligations; use rustc_middle::mir::ConstraintCategory; use rustc_middle::ty::relate::TypeRelation; use rustc_middle::ty::{self, Ty}; +use rustc_span::symbol::sym; use rustc_span::{Span, Symbol}; use rustc_trait_selection::traits::query::Fallible; @@ -125,9 +126,9 @@ impl<'tcx> TypeRelatingDelegate<'tcx> for NllTypeRelatingDelegate<'_, '_, 'tcx> let reg_info = match placeholder.bound.kind { ty::BoundRegionKind::BrAnon(Some(span)) => BoundRegionInfo::Span(span), - ty::BoundRegionKind::BrAnon(..) => BoundRegionInfo::Name(Symbol::intern("anon")), + ty::BoundRegionKind::BrAnon(..) => BoundRegionInfo::Name(sym::anon), ty::BoundRegionKind::BrNamed(_, name) => BoundRegionInfo::Name(name), - ty::BoundRegionKind::BrEnv => BoundRegionInfo::Name(Symbol::intern("env")), + ty::BoundRegionKind::BrEnv => BoundRegionInfo::Name(sym::env), }; let reg_var = diff --git a/compiler/rustc_borrowck/src/universal_regions.rs b/compiler/rustc_borrowck/src/universal_regions.rs index 68c86051364ed..35dfc1f7d129a 100644 --- a/compiler/rustc_borrowck/src/universal_regions.rs +++ b/compiler/rustc_borrowck/src/universal_regions.rs @@ -24,6 +24,7 @@ use rustc_infer::infer::NllRegionVariableOrigin; use rustc_middle::ty::fold::TypeFoldable; use rustc_middle::ty::{self, InlineConstSubsts, InlineConstSubstsParts, RegionVid, Ty, TyCtxt}; use rustc_middle::ty::{InternalSubsts, SubstsRef}; +use rustc_span::symbol::{kw, sym}; use rustc_span::Symbol; use std::iter; @@ -404,10 +405,8 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> { assert_eq!(FIRST_GLOBAL_INDEX, self.infcx.num_region_vars()); // Create the "global" region that is always free in all contexts: 'static. - let fr_static = self - .infcx - .next_nll_region_var(FR, || RegionCtxt::Free(Symbol::intern("static"))) - .to_region_vid(); + let fr_static = + self.infcx.next_nll_region_var(FR, || RegionCtxt::Free(kw::Static)).to_region_vid(); // We've now added all the global regions. The next ones we // add will be external. @@ -440,11 +439,7 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> { debug!(?r); if !indices.indices.contains_key(&r) { let region_vid = { - let name = match r.get_name() { - Some(name) => name, - _ => Symbol::intern("anon"), - }; - + let name = r.get_name_or_anon(); self.infcx.next_nll_region_var(FR, || { RegionCtxt::LateBound(BoundRegionInfo::Name(name)) }) @@ -478,11 +473,7 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> { debug!(?r); if !indices.indices.contains_key(&r) { let region_vid = { - let name = match r.get_name() { - Some(name) => name, - _ => Symbol::intern("anon"), - }; - + let name = r.get_name_or_anon(); self.infcx.next_nll_region_var(FR, || { RegionCtxt::LateBound(BoundRegionInfo::Name(name)) }) @@ -768,15 +759,10 @@ impl<'cx, 'tcx> InferCtxtExt<'tcx> for BorrowckInferCtxt<'cx, 'tcx> { T: TypeFoldable>, { self.infcx.tcx.fold_regions(value, |region, _depth| { - let name = match region.get_name() { - Some(name) => name, - _ => Symbol::intern("anon"), - }; + let name = region.get_name_or_anon(); debug!(?region, ?name); - let reg_var = self.next_nll_region_var(origin, || RegionCtxt::Free(name)); - - reg_var + self.next_nll_region_var(origin, || RegionCtxt::Free(name)) }) } @@ -797,7 +783,7 @@ impl<'cx, 'tcx> InferCtxtExt<'tcx> for BorrowckInferCtxt<'cx, 'tcx> { let region_vid = { let name = match br.kind.get_name() { Some(name) => name, - _ => Symbol::intern("anon"), + _ => sym::anon, }; self.next_nll_region_var(origin, || RegionCtxt::Bound(BoundRegionInfo::Name(name))) @@ -829,11 +815,7 @@ impl<'cx, 'tcx> InferCtxtExt<'tcx> for BorrowckInferCtxt<'cx, 'tcx> { debug!(?r); if !indices.indices.contains_key(&r) { let region_vid = { - let name = match r.get_name() { - Some(name) => name, - _ => Symbol::intern("anon"), - }; - + let name = r.get_name_or_anon(); self.next_nll_region_var(FR, || { RegionCtxt::LateBound(BoundRegionInfo::Name(name)) }) @@ -855,11 +837,7 @@ impl<'cx, 'tcx> InferCtxtExt<'tcx> for BorrowckInferCtxt<'cx, 'tcx> { debug!(?r); if !indices.indices.contains_key(&r) { let region_vid = { - let name = match r.get_name() { - Some(name) => name, - _ => Symbol::intern("anon"), - }; - + let name = r.get_name_or_anon(); self.next_nll_region_var(FR, || { RegionCtxt::LateBound(BoundRegionInfo::Name(name)) }) diff --git a/compiler/rustc_middle/src/ty/sty.rs b/compiler/rustc_middle/src/ty/sty.rs index 24cbe8e8281b6..086ceebd24d60 100644 --- a/compiler/rustc_middle/src/ty/sty.rs +++ b/compiler/rustc_middle/src/ty/sty.rs @@ -1621,19 +1621,24 @@ impl<'tcx> Region<'tcx> { pub fn get_name(self) -> Option { if self.has_name() { - let name = match *self { + match *self { ty::ReEarlyBound(ebr) => Some(ebr.name), ty::ReLateBound(_, br) => br.kind.get_name(), ty::ReFree(fr) => fr.bound_region.get_name(), ty::ReStatic => Some(kw::StaticLifetime), ty::RePlaceholder(placeholder) => placeholder.bound.kind.get_name(), _ => None, - }; - - return name; + } + } else { + None } + } - None + pub fn get_name_or_anon(self) -> Symbol { + match self.get_name() { + Some(name) => name, + None => sym::anon, + } } /// Is this region named by the user? diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index 7affad9aa0171..84a4f10b8ab13 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -357,6 +357,7 @@ symbols! { always, and, and_then, + anon, anonymous_lifetime_in_impl_trait, any, append_const_msg,