Skip to content

Commit 318e82d

Browse files
Rollup merge of rust-lang#110175 - nnethercote:symbol-cleanups, r=jackh726
Symbol cleanups r? ``@jackh726`` cc ``@b-naber``
2 parents b5a6f8d + 7975779 commit 318e82d

File tree

6 files changed

+28
-49
lines changed

6 files changed

+28
-49
lines changed

compiler/rustc_borrowck/src/renumber.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,10 @@ impl RegionCtxt {
6969
/// Used to determine the representative of a component in the strongly connected
7070
/// constraint graph
7171
pub(crate) fn preference_value(self) -> usize {
72-
let _anon = Symbol::intern("anon");
73-
7472
match self {
7573
RegionCtxt::Unknown => 1,
7674
RegionCtxt::Existential(None) => 2,
77-
RegionCtxt::Existential(Some(_anon)) | RegionCtxt::Free(_anon) => 2,
75+
RegionCtxt::Existential(Some(_)) | RegionCtxt::Free(_) => 2,
7876
RegionCtxt::Location(_) => 3,
7977
RegionCtxt::TyContext(_) => 4,
8078
_ => 5,

compiler/rustc_borrowck/src/type_check/mod.rs

+3-7
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ use rustc_middle::ty::{
3535
OpaqueHiddenType, OpaqueTypeKey, RegionVid, Ty, TyCtxt, UserType, UserTypeAnnotationIndex,
3636
};
3737
use rustc_span::def_id::CRATE_DEF_ID;
38+
use rustc_span::symbol::sym;
3839
use rustc_span::{Span, DUMMY_SP};
3940
use rustc_target::abi::{FieldIdx, FIRST_VARIANT};
4041
use rustc_trait_selection::traits::query::type_op::custom::scrape_region_constraints;
@@ -1338,18 +1339,13 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
13381339
};
13391340
let (sig, map) = tcx.replace_late_bound_regions(sig, |br| {
13401341
use crate::renumber::{BoundRegionInfo, RegionCtxt};
1341-
use rustc_span::Symbol;
13421342

13431343
let region_ctxt_fn = || {
13441344
let reg_info = match br.kind {
13451345
ty::BoundRegionKind::BrAnon(Some(span)) => BoundRegionInfo::Span(span),
1346-
ty::BoundRegionKind::BrAnon(..) => {
1347-
BoundRegionInfo::Name(Symbol::intern("anon"))
1348-
}
1346+
ty::BoundRegionKind::BrAnon(..) => BoundRegionInfo::Name(sym::anon),
13491347
ty::BoundRegionKind::BrNamed(_, name) => BoundRegionInfo::Name(name),
1350-
ty::BoundRegionKind::BrEnv => {
1351-
BoundRegionInfo::Name(Symbol::intern("env"))
1352-
}
1348+
ty::BoundRegionKind::BrEnv => BoundRegionInfo::Name(sym::env),
13531349
};
13541350

13551351
RegionCtxt::LateBound(reg_info)

compiler/rustc_borrowck/src/type_check/relate_tys.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use rustc_infer::traits::PredicateObligations;
44
use rustc_middle::mir::ConstraintCategory;
55
use rustc_middle::ty::relate::TypeRelation;
66
use rustc_middle::ty::{self, Ty};
7+
use rustc_span::symbol::sym;
78
use rustc_span::{Span, Symbol};
89
use rustc_trait_selection::traits::query::Fallible;
910

@@ -125,9 +126,9 @@ impl<'tcx> TypeRelatingDelegate<'tcx> for NllTypeRelatingDelegate<'_, '_, 'tcx>
125126

126127
let reg_info = match placeholder.bound.kind {
127128
ty::BoundRegionKind::BrAnon(Some(span)) => BoundRegionInfo::Span(span),
128-
ty::BoundRegionKind::BrAnon(..) => BoundRegionInfo::Name(Symbol::intern("anon")),
129+
ty::BoundRegionKind::BrAnon(..) => BoundRegionInfo::Name(sym::anon),
129130
ty::BoundRegionKind::BrNamed(_, name) => BoundRegionInfo::Name(name),
130-
ty::BoundRegionKind::BrEnv => BoundRegionInfo::Name(Symbol::intern("env")),
131+
ty::BoundRegionKind::BrEnv => BoundRegionInfo::Name(sym::env),
131132
};
132133

133134
let reg_var =

compiler/rustc_borrowck/src/universal_regions.rs

+10-32
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ use rustc_infer::infer::NllRegionVariableOrigin;
2424
use rustc_middle::ty::fold::TypeFoldable;
2525
use rustc_middle::ty::{self, InlineConstSubsts, InlineConstSubstsParts, RegionVid, Ty, TyCtxt};
2626
use rustc_middle::ty::{InternalSubsts, SubstsRef};
27+
use rustc_span::symbol::{kw, sym};
2728
use rustc_span::Symbol;
2829
use std::iter;
2930

@@ -404,10 +405,8 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
404405
assert_eq!(FIRST_GLOBAL_INDEX, self.infcx.num_region_vars());
405406

406407
// Create the "global" region that is always free in all contexts: 'static.
407-
let fr_static = self
408-
.infcx
409-
.next_nll_region_var(FR, || RegionCtxt::Free(Symbol::intern("static")))
410-
.to_region_vid();
408+
let fr_static =
409+
self.infcx.next_nll_region_var(FR, || RegionCtxt::Free(kw::Static)).to_region_vid();
411410

412411
// We've now added all the global regions. The next ones we
413412
// add will be external.
@@ -440,11 +439,7 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
440439
debug!(?r);
441440
if !indices.indices.contains_key(&r) {
442441
let region_vid = {
443-
let name = match r.get_name() {
444-
Some(name) => name,
445-
_ => Symbol::intern("anon"),
446-
};
447-
442+
let name = r.get_name_or_anon();
448443
self.infcx.next_nll_region_var(FR, || {
449444
RegionCtxt::LateBound(BoundRegionInfo::Name(name))
450445
})
@@ -478,11 +473,7 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
478473
debug!(?r);
479474
if !indices.indices.contains_key(&r) {
480475
let region_vid = {
481-
let name = match r.get_name() {
482-
Some(name) => name,
483-
_ => Symbol::intern("anon"),
484-
};
485-
476+
let name = r.get_name_or_anon();
486477
self.infcx.next_nll_region_var(FR, || {
487478
RegionCtxt::LateBound(BoundRegionInfo::Name(name))
488479
})
@@ -768,15 +759,10 @@ impl<'cx, 'tcx> InferCtxtExt<'tcx> for BorrowckInferCtxt<'cx, 'tcx> {
768759
T: TypeFoldable<TyCtxt<'tcx>>,
769760
{
770761
self.infcx.tcx.fold_regions(value, |region, _depth| {
771-
let name = match region.get_name() {
772-
Some(name) => name,
773-
_ => Symbol::intern("anon"),
774-
};
762+
let name = region.get_name_or_anon();
775763
debug!(?region, ?name);
776764

777-
let reg_var = self.next_nll_region_var(origin, || RegionCtxt::Free(name));
778-
779-
reg_var
765+
self.next_nll_region_var(origin, || RegionCtxt::Free(name))
780766
})
781767
}
782768

@@ -797,7 +783,7 @@ impl<'cx, 'tcx> InferCtxtExt<'tcx> for BorrowckInferCtxt<'cx, 'tcx> {
797783
let region_vid = {
798784
let name = match br.kind.get_name() {
799785
Some(name) => name,
800-
_ => Symbol::intern("anon"),
786+
_ => sym::anon,
801787
};
802788

803789
self.next_nll_region_var(origin, || RegionCtxt::Bound(BoundRegionInfo::Name(name)))
@@ -829,11 +815,7 @@ impl<'cx, 'tcx> InferCtxtExt<'tcx> for BorrowckInferCtxt<'cx, 'tcx> {
829815
debug!(?r);
830816
if !indices.indices.contains_key(&r) {
831817
let region_vid = {
832-
let name = match r.get_name() {
833-
Some(name) => name,
834-
_ => Symbol::intern("anon"),
835-
};
836-
818+
let name = r.get_name_or_anon();
837819
self.next_nll_region_var(FR, || {
838820
RegionCtxt::LateBound(BoundRegionInfo::Name(name))
839821
})
@@ -855,11 +837,7 @@ impl<'cx, 'tcx> InferCtxtExt<'tcx> for BorrowckInferCtxt<'cx, 'tcx> {
855837
debug!(?r);
856838
if !indices.indices.contains_key(&r) {
857839
let region_vid = {
858-
let name = match r.get_name() {
859-
Some(name) => name,
860-
_ => Symbol::intern("anon"),
861-
};
862-
840+
let name = r.get_name_or_anon();
863841
self.next_nll_region_var(FR, || {
864842
RegionCtxt::LateBound(BoundRegionInfo::Name(name))
865843
})

compiler/rustc_middle/src/ty/sty.rs

+10-5
Original file line numberDiff line numberDiff line change
@@ -1621,19 +1621,24 @@ impl<'tcx> Region<'tcx> {
16211621

16221622
pub fn get_name(self) -> Option<Symbol> {
16231623
if self.has_name() {
1624-
let name = match *self {
1624+
match *self {
16251625
ty::ReEarlyBound(ebr) => Some(ebr.name),
16261626
ty::ReLateBound(_, br) => br.kind.get_name(),
16271627
ty::ReFree(fr) => fr.bound_region.get_name(),
16281628
ty::ReStatic => Some(kw::StaticLifetime),
16291629
ty::RePlaceholder(placeholder) => placeholder.bound.kind.get_name(),
16301630
_ => None,
1631-
};
1632-
1633-
return name;
1631+
}
1632+
} else {
1633+
None
16341634
}
1635+
}
16351636

1636-
None
1637+
pub fn get_name_or_anon(self) -> Symbol {
1638+
match self.get_name() {
1639+
Some(name) => name,
1640+
None => sym::anon,
1641+
}
16371642
}
16381643

16391644
/// Is this region named by the user?

compiler/rustc_span/src/symbol.rs

+1
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,7 @@ symbols! {
357357
always,
358358
and,
359359
and_then,
360+
anon,
360361
anonymous_lifetime_in_impl_trait,
361362
any,
362363
append_const_msg,

0 commit comments

Comments
 (0)