Skip to content

Commit 22397bf

Browse files
committed
rustc: remove the name field from EarlyBoundRegion and BrNamed.
1 parent 29f7292 commit 22397bf

32 files changed

+142
-107
lines changed

src/librustc/ich/impls_ty.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -107,18 +107,16 @@ for ty::RegionKind {
107107
db.hash_stable(hcx, hasher);
108108
i.hash_stable(hcx, hasher);
109109
}
110-
ty::ReLateBound(db, ty::BrNamed(def_id, name)) => {
110+
ty::ReLateBound(db, ty::BrNamed(def_id)) => {
111111
db.hash_stable(hcx, hasher);
112112
def_id.hash_stable(hcx, hasher);
113-
name.hash_stable(hcx, hasher);
114113
}
115114
ty::ReLateBound(db, ty::BrEnv) => {
116115
db.hash_stable(hcx, hasher);
117116
}
118-
ty::ReEarlyBound(ty::EarlyBoundRegion { def_id, index, name }) => {
117+
ty::ReEarlyBound(ty::EarlyBoundRegion { def_id, index }) => {
119118
def_id.hash_stable(hcx, hasher);
120119
index.hash_stable(hcx, hasher);
121-
name.hash_stable(hcx, hasher);
122120
}
123121
ty::ReScope(scope) => {
124122
scope.hash_stable(hcx, hasher);
@@ -796,7 +794,7 @@ impl_stable_hash_for!(struct ty::FreeRegion {
796794

797795
impl_stable_hash_for!(enum ty::BoundRegion {
798796
BrAnon(index),
799-
BrNamed(def_id, name),
797+
BrNamed(def_id),
800798
BrFresh(index),
801799
BrEnv
802800
});

src/librustc/infer/error_reporting/mod.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -202,17 +202,19 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
202202
};
203203
let (prefix, span) = match *region {
204204
ty::ReEarlyBound(ref br) => {
205+
let name = self.generic_param_name(br.def_id);
205206
let mut sp = cm.def_span(self.hir.span(node));
206207
if let Some(param) = self.hir.get_generics(scope).and_then(|generics| {
207-
generics.get_named(&br.name)
208+
generics.get_named(&name)
208209
}) {
209210
sp = param.span;
210211
}
211-
(format!("the lifetime {} as defined on", br.name), sp)
212+
(format!("the lifetime {} as defined on", name), sp)
212213
}
213214
ty::ReFree(ty::FreeRegion {
214-
bound_region: ty::BoundRegion::BrNamed(_, ref name), ..
215+
bound_region: ty::BoundRegion::BrNamed(def_id), ..
215216
}) => {
217+
let name = self.generic_param_name(def_id);
216218
let mut sp = cm.def_span(self.hir.span(node));
217219
if let Some(param) = self.hir.get_generics(scope).and_then(|generics| {
218220
generics.get_named(&name)

src/librustc/infer/error_reporting/nice_region_error/find_anon_type.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ impl<'a, 'gcx, 'tcx> Visitor<'gcx> for FindNestedTypeVisitor<'a, 'gcx, 'tcx> {
148148
// Find the index of the named region that was part of the
149149
// error. We will then search the function parameters for a bound
150150
// region at the right depth with the same index
151-
(Some(rl::Region::EarlyBound(_, id, _)), ty::BrNamed(def_id, _)) => {
151+
(Some(rl::Region::EarlyBound(_, id, _)), ty::BrNamed(def_id)) => {
152152
debug!(
153153
"EarlyBound self.infcx.tcx.hir.local_def_id(id)={:?} \
154154
def_id={:?}",
@@ -166,7 +166,7 @@ impl<'a, 'gcx, 'tcx> Visitor<'gcx> for FindNestedTypeVisitor<'a, 'gcx, 'tcx> {
166166
// region at the right depth with the same index
167167
(
168168
Some(rl::Region::LateBound(debruijn_index, id, _)),
169-
ty::BrNamed(def_id, _),
169+
ty::BrNamed(def_id),
170170
) => {
171171
debug!(
172172
"FindNestedTypeVisitor::visit_ty: LateBound depth = {:?}",
@@ -241,7 +241,7 @@ impl<'a, 'gcx, 'tcx> Visitor<'gcx> for TyPathVisitor<'a, 'gcx, 'tcx> {
241241
}
242242
}
243243

244-
(Some(rl::Region::EarlyBound(_, id, _)), ty::BrNamed(def_id, _)) => {
244+
(Some(rl::Region::EarlyBound(_, id, _)), ty::BrNamed(def_id)) => {
245245
debug!(
246246
"EarlyBound self.infcx.tcx.hir.local_def_id(id)={:?} \
247247
def_id={:?}",
@@ -254,7 +254,7 @@ impl<'a, 'gcx, 'tcx> Visitor<'gcx> for TyPathVisitor<'a, 'gcx, 'tcx> {
254254
}
255255
}
256256

257-
(Some(rl::Region::LateBound(debruijn_index, id, _)), ty::BrNamed(def_id, _)) => {
257+
(Some(rl::Region::LateBound(debruijn_index, id, _)), ty::BrNamed(def_id)) => {
258258
debug!(
259259
"FindNestedTypeVisitor::visit_ty: LateBound depth = {:?}",
260260
debruijn_index,

src/librustc/infer/error_reporting/nice_region_error/named_anon_conflict.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> {
129129
ty::BrNamed(..) => true,
130130
_ => false,
131131
},
132-
ty::ReEarlyBound(ebr) => ebr.has_name(),
132+
ty::ReEarlyBound(ebr) => ebr.has_name(self.tcx),
133133
_ => false,
134134
}
135135
}

src/librustc/infer/error_reporting/nice_region_error/static_impl_trait.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> {
5656

5757
let lifetime_name = match sup_r {
5858
RegionKind::ReFree(FreeRegion {
59-
bound_region: BoundRegion::BrNamed(_, ref name), ..
60-
}) => name.to_string(),
59+
bound_region: BoundRegion::BrNamed(def_id), ..
60+
}) => self.tcx.generic_param_name(*def_id).to_string(),
6161
_ => "'_".to_owned(),
6262
};
6363
if let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(return_sp) {

src/librustc/infer/error_reporting/nice_region_error/util.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> {
6767
ty::ReFree(ref free_region) => (free_region.scope, free_region.bound_region),
6868
ty::ReEarlyBound(ref ebr) => (
6969
self.tcx.parent_def_id(ebr.def_id).unwrap(),
70-
ty::BoundRegion::BrNamed(ebr.def_id, ebr.name),
70+
ty::BoundRegion::BrNamed(ebr.def_id),
7171
),
7272
_ => return None, // not a free region
7373
};
@@ -127,7 +127,7 @@ impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> {
127127
ty::ReFree(ref free_region) => (free_region.scope, free_region.bound_region),
128128
ty::ReEarlyBound(ref ebr) => (
129129
self.tcx.parent_def_id(ebr.def_id).unwrap(),
130-
ty::BoundRegion::BrNamed(ebr.def_id, ebr.name),
130+
ty::BoundRegion::BrNamed(ebr.def_id),
131131
),
132132
_ => return None, // not a free region
133133
};

src/librustc/middle/region.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -750,9 +750,7 @@ impl<'tcx> ScopeTree {
750750
pub fn free_scope<'a, 'gcx>(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>, fr: &ty::FreeRegion)
751751
-> Scope {
752752
let param_owner = match fr.bound_region {
753-
ty::BoundRegion::BrNamed(def_id, _) => {
754-
tcx.parent_def_id(def_id).unwrap()
755-
}
753+
ty::BoundRegion::BrNamed(def_id) => tcx.generic_param_owner(def_id),
756754
_ => fr.scope
757755
};
758756

src/librustc/traits/auto_trait.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
482482

483483
pub fn region_name(&self, region: Region) -> Option<String> {
484484
match region {
485-
&ty::ReEarlyBound(r) => Some(r.name.to_string()),
485+
&ty::ReEarlyBound(r) => Some(self.tcx.generic_param_name(r.def_id).to_string()),
486486
_ => None,
487487
}
488488
}

src/librustc/ty/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -821,13 +821,14 @@ pub struct FloatVarValue(pub ast::FloatTy);
821821

822822
impl ty::EarlyBoundRegion {
823823
pub fn to_bound_region(&self) -> ty::BoundRegion {
824-
ty::BoundRegion::BrNamed(self.def_id, self.name)
824+
ty::BoundRegion::BrNamed(self.def_id)
825825
}
826826

827827
/// Does this early bound region have a name? Early bound regions normally
828828
/// always have names except when using anonymous lifetimes (`'_`).
829-
pub fn has_name(&self) -> bool {
830-
self.name != keywords::UnderscoreLifetime.name().as_interned_str()
829+
pub fn has_name(&self, tcx: TyCtxt) -> bool {
830+
let name = tcx.generic_param_name(self.def_id);
831+
name != keywords::UnderscoreLifetime.name().as_interned_str()
831832
}
832833
}
833834

@@ -862,7 +863,6 @@ impl GenericParamDef {
862863
ty::EarlyBoundRegion {
863864
def_id: self.def_id,
864865
index: self.index,
865-
name: self.name,
866866
}
867867
}
868868
_ => bug!("cannot convert a non-lifetime parameter def to an early bound region")

src/librustc/ty/sty.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ use std::iter;
2626
use std::cmp::Ordering;
2727
use rustc_target::spec::abi;
2828
use syntax::ast::{self, Ident};
29-
use syntax::symbol::InternedString;
3029

3130
use serialize;
3231

@@ -60,7 +59,7 @@ pub enum BoundRegion {
6059
///
6160
/// The def-id is needed to distinguish free regions in
6261
/// the event of shadowing.
63-
BrNamed(DefId, InternedString),
62+
BrNamed(DefId),
6463

6564
/// Fresh bound identifiers created during GLB computations.
6665
BrFresh(u32),
@@ -1129,7 +1128,6 @@ impl<'tcx> serialize::UseSpecializedDecodable for Region<'tcx> {}
11291128
pub struct EarlyBoundRegion {
11301129
pub def_id: DefId,
11311130
pub index: u32,
1132-
pub name: InternedString,
11331131
}
11341132

11351133
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable)]

src/librustc/ty/subst.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ impl<'a, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for SubstFolder<'a, 'gcx, 'tcx> {
453453
"Region parameter out of range \
454454
when substituting in region {} (root type={:?}) \
455455
(index={})",
456-
data.name,
456+
self.tcx().generic_param_name(data.def_id),
457457
self.root_ty,
458458
data.index);
459459
}

0 commit comments

Comments
 (0)