Skip to content

Commit 8bf5e85

Browse files
committed
Use Symbol in ParamTy.
This removes the need for a lot of `as_str()` and `as_interned_str()` calls.
1 parent fe5f42c commit 8bf5e85

File tree

21 files changed

+76
-78
lines changed

21 files changed

+76
-78
lines changed

src/librustc/hir/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use crate::util::nodemap::{NodeMap, FxHashSet};
1616
use crate::mir::mono::Linkage;
1717

1818
use errors::FatalError;
19-
use syntax_pos::{Span, DUMMY_SP, symbol::InternedString};
19+
use syntax_pos::{Span, DUMMY_SP};
2020
use syntax::source_map::Spanned;
2121
use rustc_target::spec::abi::Abi;
2222
use syntax::ast::{self, CrateSugar, Ident, Name, NodeId, AsmDialect};
@@ -609,9 +609,9 @@ impl Generics {
609609
own_counts
610610
}
611611

612-
pub fn get_named(&self, name: &InternedString) -> Option<&GenericParam> {
612+
pub fn get_named(&self, name: Symbol) -> Option<&GenericParam> {
613613
for param in &self.params {
614-
if *name == param.name.ident().as_interned_str() {
614+
if name == param.name.ident().name {
615615
return Some(param);
616616
}
617617
}

src/librustc/infer/error_reporting/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -194,20 +194,20 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
194194
let mut sp = cm.def_span(self.hir().span_by_hir_id(node));
195195
if let Some(param) = self.hir()
196196
.get_generics(scope)
197-
.and_then(|generics| generics.get_named(&br.name))
197+
.and_then(|generics| generics.get_named(br.name))
198198
{
199199
sp = param.span;
200200
}
201201
(format!("the lifetime {} as defined on", br.name), sp)
202202
}
203203
ty::ReFree(ty::FreeRegion {
204-
bound_region: ty::BoundRegion::BrNamed(_, ref name),
204+
bound_region: ty::BoundRegion::BrNamed(_, name),
205205
..
206206
}) => {
207207
let mut sp = cm.def_span(self.hir().span_by_hir_id(node));
208208
if let Some(param) = self.hir()
209209
.get_generics(scope)
210-
.and_then(|generics| generics.get_named(&name))
210+
.and_then(|generics| generics.get_named(name))
211211
{
212212
sp = param.span;
213213
}

src/librustc/infer/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ use std::cell::{Cell, Ref, RefCell, RefMut};
3232
use std::collections::BTreeMap;
3333
use std::fmt;
3434
use syntax::ast;
35-
use syntax_pos::symbol::InternedString;
35+
use syntax_pos::symbol::Symbol;
3636
use syntax_pos::Span;
3737

3838
use self::combine::CombineFields;
@@ -383,7 +383,7 @@ pub enum RegionVariableOrigin {
383383
Coercion(Span),
384384

385385
/// Region variables created as the values for early-bound regions
386-
EarlyBoundRegion(Span, InternedString),
386+
EarlyBoundRegion(Span, Symbol),
387387

388388
/// Region variables created for bound regions
389389
/// in a function or method that is called

src/librustc/infer/type_variable.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use syntax::symbol::InternedString;
1+
use syntax::symbol::Symbol;
22
use syntax_pos::Span;
33
use crate::ty::{self, Ty, TyVid};
44

@@ -43,7 +43,7 @@ pub enum TypeVariableOrigin {
4343
MiscVariable(Span),
4444
NormalizeProjectionType(Span),
4545
TypeInference(Span),
46-
TypeParameterDefinition(Span, InternedString),
46+
TypeParameterDefinition(Span, Symbol),
4747

4848
/// one of the upvars or closure kind parameters in a `ClosureSubsts`
4949
/// (before it has been determined)

src/librustc/infer/unify_key.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::mir::interpret::ConstValue;
33
use rustc_data_structures::unify::{NoError, EqUnifyValue, UnifyKey, UnifyValue, UnificationTable};
44
use rustc_data_structures::unify::InPlace;
55
use syntax_pos::{Span, DUMMY_SP};
6-
use syntax::symbol::InternedString;
6+
use syntax::symbol::Symbol;
77

88
use std::cmp;
99
use std::marker::PhantomData;
@@ -84,7 +84,7 @@ impl ToType for FloatVarValue {
8484
pub enum ConstVariableOrigin {
8585
MiscVariable(Span),
8686
ConstInference(Span),
87-
ConstParameterDefinition(Span, InternedString),
87+
ConstParameterDefinition(Span, Symbol),
8888
SubstitutionPlaceholder(Span),
8989
}
9090

src/librustc/traits/object_safety.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> {
539539
// are implemented
540540
let unsized_self_ty: Ty<'tcx> = self.mk_ty_param(
541541
::std::u32::MAX,
542-
Name::intern("RustaceansAreAwesome").as_interned_str(),
542+
Name::intern("RustaceansAreAwesome"),
543543
);
544544

545545
// `Receiver[Self => U]`

src/librustc/traits/on_unimplemented.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ impl<'a, 'gcx, 'tcx> OnUnimplementedFormatString {
250250
Position::ArgumentNamed(s) if s == "from_desugaring" => (),
251251
// So is `{A}` if A is a type parameter
252252
Position::ArgumentNamed(s) => match generics.params.iter().find(|param|
253-
param.name == s
253+
param.name.as_str() == s
254254
) {
255255
Some(_) => (),
256256
None => {

src/librustc/traits/structural_impls.rs

+5-9
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::traits;
44
use crate::traits::project::Normalized;
55
use crate::ty::fold::{TypeFoldable, TypeFolder, TypeVisitor};
66
use crate::ty::{self, Lift, Ty, TyCtxt};
7-
use syntax::symbol::InternedString;
7+
use syntax::symbol::Symbol;
88

99
use std::fmt;
1010
use std::rc::Rc;
@@ -261,11 +261,11 @@ impl fmt::Display for traits::QuantifierKind {
261261
/// for debug output in tests anyway.
262262
struct BoundNamesCollector {
263263
// Just sort by name because `BoundRegion::BrNamed` does not have a `BoundVar` index anyway.
264-
regions: BTreeSet<InternedString>,
264+
regions: BTreeSet<Symbol>,
265265

266266
// Sort by `BoundVar` index, so usually this should be equivalent to the order given
267267
// by the list of type parameters.
268-
types: BTreeMap<u32, InternedString>,
268+
types: BTreeMap<u32, Symbol>,
269269

270270
binder_index: ty::DebruijnIndex,
271271
}
@@ -312,8 +312,6 @@ impl<'tcx> TypeVisitor<'tcx> for BoundNamesCollector {
312312
}
313313

314314
fn visit_ty(&mut self, t: Ty<'tcx>) -> bool {
315-
use syntax::symbol::Symbol;
316-
317315
match t.sty {
318316
ty::Bound(debruijn, bound_ty) if debruijn == self.binder_index => {
319317
self.types.insert(
@@ -322,7 +320,7 @@ impl<'tcx> TypeVisitor<'tcx> for BoundNamesCollector {
322320
ty::BoundTyKind::Param(name) => name,
323321
ty::BoundTyKind::Anon => Symbol::intern(
324322
&format!("^{}", bound_ty.var.as_u32())
325-
).as_interned_str(),
323+
),
326324
}
327325
);
328326
}
@@ -334,8 +332,6 @@ impl<'tcx> TypeVisitor<'tcx> for BoundNamesCollector {
334332
}
335333

336334
fn visit_region(&mut self, r: ty::Region<'tcx>) -> bool {
337-
use syntax::symbol::Symbol;
338-
339335
match r {
340336
ty::ReLateBound(index, br) if *index == self.binder_index => {
341337
match br {
@@ -346,7 +342,7 @@ impl<'tcx> TypeVisitor<'tcx> for BoundNamesCollector {
346342
ty::BoundRegion::BrAnon(var) => {
347343
self.regions.insert(Symbol::intern(
348344
&format!("'^{}", var)
349-
).as_interned_str());
345+
));
350346
}
351347

352348
_ => (),

src/librustc/ty/context.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ use syntax::ast;
7474
use syntax::attr;
7575
use syntax::source_map::MultiSpan;
7676
use syntax::feature_gate;
77-
use syntax::symbol::{Symbol, keywords, InternedString, sym};
77+
use syntax::symbol::{Symbol, keywords, sym};
7878
use syntax_pos::Span;
7979

8080
use crate::hir;
@@ -2716,15 +2716,15 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
27162716
}
27172717

27182718
#[inline]
2719-
pub fn mk_ty_param(self, index: u32, name: InternedString) -> Ty<'tcx> {
2719+
pub fn mk_ty_param(self, index: u32, name: Symbol) -> Ty<'tcx> {
27202720
self.mk_ty(Param(ParamTy { index, name: name }))
27212721
}
27222722

27232723
#[inline]
27242724
pub fn mk_const_param(
27252725
self,
27262726
index: u32,
2727-
name: InternedString,
2727+
name: Symbol,
27282728
ty: Ty<'tcx>
27292729
) -> &'tcx Const<'tcx> {
27302730
self.mk_const(ty::Const {
@@ -2735,7 +2735,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
27352735

27362736
#[inline]
27372737
pub fn mk_self_type(self) -> Ty<'tcx> {
2738-
self.mk_ty_param(0, keywords::SelfUpper.name().as_interned_str())
2738+
self.mk_ty_param(0, keywords::SelfUpper.name())
27392739
}
27402740

27412741
pub fn mk_param_from_def(self, param: &ty::GenericParamDef) -> Kind<'tcx> {

src/librustc/ty/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -835,7 +835,7 @@ impl ty::EarlyBoundRegion {
835835
/// Does this early bound region have a name? Early bound regions normally
836836
/// always have names except when using anonymous lifetimes (`'_`).
837837
pub fn has_name(&self) -> bool {
838-
self.name != keywords::UnderscoreLifetime.name().as_interned_str()
838+
self.name != keywords::UnderscoreLifetime.name()
839839
}
840840
}
841841

@@ -852,7 +852,7 @@ pub enum GenericParamDefKind {
852852

853853
#[derive(Clone, RustcEncodable, RustcDecodable, HashStable)]
854854
pub struct GenericParamDef {
855-
pub name: InternedString,
855+
pub name: Symbol,
856856
pub def_id: DefId,
857857
pub index: u32,
858858

src/librustc/ty/print/pretty.rs

+11-9
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ use crate::mir::interpret::ConstValue;
1010
use syntax::symbol::{keywords, Symbol};
1111

1212
use rustc_target::spec::abi::Abi;
13-
use syntax::symbol::InternedString;
1413

1514
use std::cell::Cell;
1615
use std::fmt::{self, Write as _};
@@ -818,7 +817,7 @@ pub struct FmtPrinterData<'a, 'gcx, 'tcx, F> {
818817
empty_path: bool,
819818
in_value: bool,
820819

821-
used_region_names: FxHashSet<InternedString>,
820+
used_region_names: FxHashSet<Symbol>,
822821
region_index: usize,
823822
binder_depth: usize,
824823

@@ -1142,14 +1141,16 @@ impl<F: fmt::Write> PrettyPrinter<'gcx, 'tcx> for FmtPrinter<'_, 'gcx, 'tcx, F>
11421141

11431142
match *region {
11441143
ty::ReEarlyBound(ref data) => {
1145-
data.name != "" && data.name != "'_"
1144+
data.name != keywords::Invalid.name() &&
1145+
data.name != keywords::UnderscoreLifetime.name()
11461146
}
11471147

11481148
ty::ReLateBound(_, br) |
11491149
ty::ReFree(ty::FreeRegion { bound_region: br, .. }) |
11501150
ty::RePlaceholder(ty::Placeholder { name: br, .. }) => {
11511151
if let ty::BrNamed(_, name) = br {
1152-
if name != "" && name != "'_" {
1152+
if name != keywords::Invalid.name() &&
1153+
name != keywords::UnderscoreLifetime.name() {
11531154
return true;
11541155
}
11551156
}
@@ -1205,7 +1206,7 @@ impl<F: fmt::Write> FmtPrinter<'_, '_, '_, F> {
12051206
// `explain_region()` or `note_and_explain_region()`.
12061207
match *region {
12071208
ty::ReEarlyBound(ref data) => {
1208-
if data.name != "" {
1209+
if data.name != keywords::Invalid.name() {
12091210
p!(write("{}", data.name));
12101211
return Ok(self);
12111212
}
@@ -1214,7 +1215,8 @@ impl<F: fmt::Write> FmtPrinter<'_, '_, '_, F> {
12141215
ty::ReFree(ty::FreeRegion { bound_region: br, .. }) |
12151216
ty::RePlaceholder(ty::Placeholder { name: br, .. }) => {
12161217
if let ty::BrNamed(_, name) = br {
1217-
if name != "" && name != "'_" {
1218+
if name != keywords::Invalid.name() &&
1219+
name != keywords::UnderscoreLifetime.name() {
12181220
p!(write("{}", name));
12191221
return Ok(self);
12201222
}
@@ -1283,12 +1285,12 @@ impl<F: fmt::Write> FmtPrinter<'_, 'gcx, 'tcx, F> {
12831285
) -> Result<Self, fmt::Error>
12841286
where T: Print<'gcx, 'tcx, Self, Output = Self, Error = fmt::Error> + TypeFoldable<'tcx>
12851287
{
1286-
fn name_by_region_index(index: usize) -> InternedString {
1288+
fn name_by_region_index(index: usize) -> Symbol {
12871289
match index {
12881290
0 => Symbol::intern("'r"),
12891291
1 => Symbol::intern("'s"),
12901292
i => Symbol::intern(&format!("'t{}", i-2)),
1291-
}.as_interned_str()
1293+
}
12921294
}
12931295

12941296
// Replace any anonymous late-bound regions with named
@@ -1351,7 +1353,7 @@ impl<F: fmt::Write> FmtPrinter<'_, 'gcx, 'tcx, F> {
13511353
where T: TypeFoldable<'tcx>
13521354
{
13531355

1354-
struct LateBoundRegionNameCollector<'a>(&'a mut FxHashSet<InternedString>);
1356+
struct LateBoundRegionNameCollector<'a>(&'a mut FxHashSet<Symbol>);
13551357
impl<'tcx> ty::fold::TypeVisitor<'tcx> for LateBoundRegionNameCollector<'_> {
13561358
fn visit_region(&mut self, r: ty::Region<'tcx>) -> bool {
13571359
match *r {

src/librustc/ty/sty.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use std::marker::PhantomData;
2222
use std::ops::Range;
2323
use rustc_target::spec::abi;
2424
use syntax::ast::{self, Ident};
25-
use syntax::symbol::{keywords, InternedString};
25+
use syntax::symbol::{keywords, Symbol};
2626

2727
use serialize;
2828
use self::InferTy::*;
@@ -54,7 +54,7 @@ pub enum BoundRegion {
5454
///
5555
/// The `DefId` is needed to distinguish free regions in
5656
/// the event of shadowing.
57-
BrNamed(DefId, InternedString),
57+
BrNamed(DefId, Symbol),
5858

5959
/// Fresh bound identifiers created during GLB computations.
6060
BrFresh(u32),
@@ -1112,16 +1112,16 @@ pub type CanonicalPolyFnSig<'tcx> = Canonical<'tcx, Binder<FnSig<'tcx>>>;
11121112
Hash, RustcEncodable, RustcDecodable, HashStable)]
11131113
pub struct ParamTy {
11141114
pub index: u32,
1115-
pub name: InternedString,
1115+
pub name: Symbol,
11161116
}
11171117

11181118
impl<'a, 'gcx, 'tcx> ParamTy {
1119-
pub fn new(index: u32, name: InternedString) -> ParamTy {
1119+
pub fn new(index: u32, name: Symbol) -> ParamTy {
11201120
ParamTy { index, name: name }
11211121
}
11221122

11231123
pub fn for_self() -> ParamTy {
1124-
ParamTy::new(0, keywords::SelfUpper.name().as_interned_str())
1124+
ParamTy::new(0, keywords::SelfUpper.name())
11251125
}
11261126

11271127
pub fn for_def(def: &ty::GenericParamDef) -> ParamTy {
@@ -1136,19 +1136,19 @@ impl<'a, 'gcx, 'tcx> ParamTy {
11361136
// FIXME(#50125): Ignoring `Self` with `index != 0` might lead to weird behavior elsewhere,
11371137
// but this should only be possible when using `-Z continue-parse-after-error` like
11381138
// `compile-fail/issue-36638.rs`.
1139-
self.name == keywords::SelfUpper.name().as_str() && self.index == 0
1139+
self.name == keywords::SelfUpper.name() && self.index == 0
11401140
}
11411141
}
11421142

11431143
#[derive(Copy, Clone, Hash, RustcEncodable, RustcDecodable,
11441144
Eq, PartialEq, Ord, PartialOrd, HashStable)]
11451145
pub struct ParamConst {
11461146
pub index: u32,
1147-
pub name: InternedString,
1147+
pub name: Symbol,
11481148
}
11491149

11501150
impl<'a, 'gcx, 'tcx> ParamConst {
1151-
pub fn new(index: u32, name: InternedString) -> ParamConst {
1151+
pub fn new(index: u32, name: Symbol) -> ParamConst {
11521152
ParamConst { index, name }
11531153
}
11541154

@@ -1321,7 +1321,7 @@ impl<'tcx> serialize::UseSpecializedDecodable for Region<'tcx> {}
13211321
pub struct EarlyBoundRegion {
13221322
pub def_id: DefId,
13231323
pub index: u32,
1324-
pub name: InternedString,
1324+
pub name: Symbol,
13251325
}
13261326

13271327
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable)]
@@ -1385,7 +1385,7 @@ pub struct BoundTy {
13851385
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, RustcEncodable, RustcDecodable)]
13861386
pub enum BoundTyKind {
13871387
Anon,
1388-
Param(InternedString),
1388+
Param(Symbol),
13891389
}
13901390

13911391
impl_stable_hash_for!(struct BoundTy { var, kind });

0 commit comments

Comments
 (0)