Skip to content

Commit 299a722

Browse files
committed
rustc: combine ty::{ParamTy, EarlyBoundRegion} into GenericParam.
1 parent d337a3b commit 299a722

35 files changed

+71
-85
lines changed

src/librustc/ich/impls_ty.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ for ty::RegionKind {
114114
ty::ReLateBound(db, ty::BrEnv) => {
115115
db.hash_stable(hcx, hasher);
116116
}
117-
ty::ReEarlyBound(ty::EarlyBoundRegion { def_id, index }) => {
117+
ty::ReEarlyBound(ty::GenericParam { def_id, index }) => {
118118
def_id.hash_stable(hcx, hasher);
119119
index.hash_stable(hcx, hasher);
120120
}
@@ -935,8 +935,8 @@ for ty::FloatVid
935935
}
936936
}
937937

938-
impl_stable_hash_for!(struct ty::ParamTy {
939-
idx,
938+
impl_stable_hash_for!(struct ty::GenericParam {
939+
index,
940940
def_id
941941
});
942942

src/librustc/infer/outlives/obligations.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ where
330330
&mut self,
331331
origin: infer::SubregionOrigin<'tcx>,
332332
region: ty::Region<'tcx>,
333-
param_ty: ty::ParamTy,
333+
param_ty: ty::GenericParam,
334334
) {
335335
debug!(
336336
"param_ty_must_outlive(region={:?}, param_ty={:?}, origin={:?})",
@@ -459,7 +459,7 @@ where
459459
}
460460
}
461461

462-
fn param_bound(&self, param_ty: ty::ParamTy) -> VerifyBound<'tcx> {
462+
fn param_bound(&self, param_ty: ty::GenericParam) -> VerifyBound<'tcx> {
463463
debug!("param_bound(param_ty={:?})", param_ty);
464464

465465
let mut param_bounds = self.declared_generic_bounds_from_env(GenericKind::Param(param_ty));

src/librustc/infer/region_constraints/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ pub struct Verify<'tcx> {
151151

152152
#[derive(Copy, Clone, PartialEq, Eq)]
153153
pub enum GenericKind<'tcx> {
154-
Param(ty::ParamTy),
154+
Param(ty::GenericParam),
155155
Projection(ty::ProjectionTy<'tcx>),
156156
}
157157

src/librustc/middle/region.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,7 @@ impl<'tcx> ScopeTree {
720720
/// Assuming that the provided region was defined within this `ScopeTree`,
721721
/// returns the outermost `Scope` that the region outlives.
722722
pub fn early_free_scope<'a, 'gcx>(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>,
723-
br: &ty::EarlyBoundRegion)
723+
br: &ty::GenericParam)
724724
-> Scope {
725725
let param_owner = tcx.parent_def_id(br.def_id).unwrap();
726726

src/librustc/traits/error_reporting.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1348,7 +1348,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
13481348
fn tcx<'b>(&'b self) -> TyCtxt<'b, 'gcx, 'tcx> { self.infcx.tcx }
13491349

13501350
fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> {
1351-
if let ty::Param(ty::ParamTy {def_id, ..}) = ty.sty {
1351+
if let ty::Param(ty::GenericParam {def_id, ..}) = ty.sty {
13521352
let infcx = self.infcx;
13531353
self.var_map.entry(ty).or_insert_with(||
13541354
infcx.next_ty_var(

src/librustc/traits/query/outlives_bounds.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use std::mem;
3131
#[derive(Clone, Debug)]
3232
pub enum OutlivesBound<'tcx> {
3333
RegionSubRegion(ty::Region<'tcx>, ty::Region<'tcx>),
34-
RegionSubParam(ty::Region<'tcx>, ty::ParamTy),
34+
RegionSubParam(ty::Region<'tcx>, ty::GenericParam),
3535
RegionSubProjection(ty::Region<'tcx>, ty::ProjectionTy<'tcx>),
3636
}
3737

src/librustc/traits/select.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3073,7 +3073,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
30733073
let mut found = false;
30743074
for ty in field.walk() {
30753075
if let ty::Param(p) = ty.sty {
3076-
ty_params.insert(p.idx as usize);
3076+
ty_params.insert(p.index as usize);
30773077
found = true;
30783078
}
30793079
}

src/librustc/ty/context.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -2557,15 +2557,15 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
25572557
}
25582558

25592559
pub fn mk_ty_param(self, def: &ty::GenericParamDef) -> Ty<'tcx> {
2560-
self.mk_ty(ty::Param(ty::ParamTy {
2561-
idx: def.index,
2560+
self.mk_ty(ty::Param(ty::GenericParam {
2561+
index: def.index,
25622562
def_id: def.def_id,
25632563
}))
25642564
}
25652565

25662566
pub fn mk_self_type(self, trait_def_id: DefId) -> Ty<'tcx> {
2567-
self.mk_ty(ty::Param(ty::ParamTy {
2568-
idx: 0,
2567+
self.mk_ty(ty::Param(ty::GenericParam {
2568+
index: 0,
25692569
def_id: trait_def_id,
25702570
}))
25712571
}

src/librustc/ty/mod.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,12 @@ use hir;
6363

6464
pub use self::sty::{Binder, CanonicalVar, DebruijnIndex, INNERMOST};
6565
pub use self::sty::{FnSig, GenSig, PolyFnSig, PolyGenSig};
66-
pub use self::sty::{InferTy, ParamTy, ProjectionTy, ExistentialPredicate};
66+
pub use self::sty::{InferTy, GenericParam, ProjectionTy, ExistentialPredicate};
6767
pub use self::sty::{ClosureSubsts, GeneratorSubsts, UpvarSubsts, TypeAndMut};
6868
pub use self::sty::{TraitRef, TyKind, PolyTraitRef};
6969
pub use self::sty::{ExistentialTraitRef, PolyExistentialTraitRef};
7070
pub use self::sty::{ExistentialProjection, PolyExistentialProjection, Const};
71-
pub use self::sty::{BoundRegion, EarlyBoundRegion, FreeRegion, Region};
71+
pub use self::sty::{BoundRegion, FreeRegion, Region};
7272
pub use self::sty::RegionKind;
7373
pub use self::sty::{TyVid, IntVid, FloatVid, RegionVid};
7474
pub use self::sty::BoundRegion::*;
@@ -819,7 +819,7 @@ pub enum IntVarValue {
819819
#[derive(Clone, Copy, PartialEq, Eq)]
820820
pub struct FloatVarValue(pub ast::FloatTy);
821821

822-
impl ty::EarlyBoundRegion {
822+
impl ty::GenericParam {
823823
pub fn to_bound_region(&self) -> ty::BoundRegion {
824824
ty::BoundRegion::BrNamed(self.def_id)
825825
}
@@ -856,10 +856,10 @@ pub struct GenericParamDef {
856856
}
857857

858858
impl GenericParamDef {
859-
pub fn to_early_bound_region_data(&self) -> ty::EarlyBoundRegion {
859+
pub fn to_early_bound_region_data(&self) -> ty::GenericParam {
860860
match self.kind {
861861
GenericParamDefKind::Lifetime => {
862-
ty::EarlyBoundRegion {
862+
ty::GenericParam {
863863
def_id: self.def_id,
864864
index: self.index,
865865
}
@@ -2657,7 +2657,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
26572657
if let Some(trait_ref) = predicate.to_opt_poly_trait_ref() {
26582658
// Ignore bounds other than those on this parameter.
26592659
match trait_ref.self_ty().sty {
2660-
ty::TyParam(p) if p.def_id == id => {}
2660+
ty::Param(p) if p.def_id == id => {}
26612661
_ => continue,
26622662
}
26632663

src/librustc/ty/outlives.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use ty::{self, Ty, TyCtxt, TypeFoldable};
1717
#[derive(Debug)]
1818
pub enum Component<'tcx> {
1919
Region(ty::Region<'tcx>),
20-
Param(ty::ParamTy),
20+
Param(ty::GenericParam),
2121
UnresolvedInferenceVariable(ty::InferTy),
2222

2323
// Projections like `T::Foo` are tricky because a constraint like

src/librustc/ty/relate.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ pub fn super_relate_tys<'a, 'gcx, 'tcx, R>(relation: &mut R,
388388
}
389389

390390
(&ty::Param(ref a_p), &ty::Param(ref b_p))
391-
if a_p.idx == b_p.idx =>
391+
if a_p.index == b_p.index =>
392392
{
393393
Ok(a)
394394
}

src/librustc/ty/structural_impls.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ CloneTypeFoldableAndLiftImpls! {
5656
::ty::BoundRegion,
5757
::ty::ClosureKind,
5858
::ty::IntVarValue,
59-
::ty::ParamTy,
59+
::ty::GenericParam,
6060
::syntax_pos::Span,
6161
}
6262

src/librustc/ty/sty.rs

+5-11
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ pub enum TyKind<'tcx> {
165165
Anon(DefId, &'tcx Substs<'tcx>),
166166

167167
/// A type parameter; for example, `T` in `fn f<T>(x: T) {}
168-
Param(ParamTy),
168+
Param(GenericParam),
169169

170170
/// A type variable used during type-checking.
171171
Infer(InferTy),
@@ -959,12 +959,6 @@ impl<'tcx> PolyFnSig<'tcx> {
959959
}
960960
}
961961

962-
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable)]
963-
pub struct ParamTy {
964-
pub idx: u32,
965-
pub def_id: DefId,
966-
}
967-
968962
/// A [De Bruijn index][dbi] is a standard means of representing
969963
/// regions (and perhaps later types) in a higher-ranked setting. In
970964
/// particular, imagine a type like this:
@@ -1074,7 +1068,7 @@ pub enum RegionKind {
10741068
// Region bound in a type or fn declaration which will be
10751069
// substituted 'early' -- that is, at the same time when type
10761070
// parameters are substituted.
1077-
ReEarlyBound(EarlyBoundRegion),
1071+
ReEarlyBound(GenericParam),
10781072

10791073
// Region bound in a function scope, which will be substituted when the
10801074
// function is called.
@@ -1124,8 +1118,8 @@ pub enum RegionKind {
11241118

11251119
impl<'tcx> serialize::UseSpecializedDecodable for Region<'tcx> {}
11261120

1127-
#[derive(Copy, Clone, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable, Debug, PartialOrd, Ord)]
1128-
pub struct EarlyBoundRegion {
1121+
#[derive(Copy, Clone, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable, PartialOrd, Ord)]
1122+
pub struct GenericParam {
11291123
pub def_id: DefId,
11301124
pub index: u32,
11311125
}
@@ -1483,7 +1477,7 @@ impl<'a, 'gcx, 'tcx> TyS<'tcx> {
14831477

14841478
pub fn is_param(&self, index: u32) -> bool {
14851479
match self.sty {
1486-
ty::Param(ref data) => data.idx == index,
1480+
ty::Param(ref data) => data.index == index,
14871481
_ => false,
14881482
}
14891483
}

src/librustc/ty/subst.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -495,9 +495,9 @@ impl<'a, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for SubstFolder<'a, 'gcx, 'tcx> {
495495
}
496496

497497
impl<'a, 'gcx, 'tcx> SubstFolder<'a, 'gcx, 'tcx> {
498-
fn ty_for_param(&self, p: ty::ParamTy, source_ty: Ty<'tcx>) -> Ty<'tcx> {
498+
fn ty_for_param(&self, p: ty::GenericParam, source_ty: Ty<'tcx>) -> Ty<'tcx> {
499499
// Look up the type in the substitutions. It really should be in there.
500-
let opt_ty = self.substs.get(p.idx as usize).map(|k| k.unpack());
500+
let opt_ty = self.substs.get(p.index as usize).map(|k| k.unpack());
501501
let ty = match opt_ty {
502502
Some(UnpackedKind::Type(ty)) => ty,
503503
_ => {
@@ -508,7 +508,7 @@ impl<'a, 'gcx, 'tcx> SubstFolder<'a, 'gcx, 'tcx> {
508508
when substituting (root type={:?}) substs={:?}",
509509
p,
510510
source_ty,
511-
p.idx,
511+
p.index,
512512
self.root_ty,
513513
self.substs);
514514
}

src/librustc/ty/util.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -498,19 +498,18 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
498498

499499
let result = item_substs.iter().zip(impl_substs.iter())
500500
.filter(|&(_, &k)| {
501-
let index = match k.unpack() {
502-
UnpackedKind::Lifetime(&ty::RegionKind::ReEarlyBound(ref ebr)) =>
503-
ebr.index,
501+
let param = match k.unpack() {
502+
UnpackedKind::Lifetime(&ty::RegionKind::ReEarlyBound(ref ebr)) => ebr,
504503
UnpackedKind::Type(&ty::TyS {
505504
sty: ty::Param(ref pt), ..
506-
}) => pt.idx,
505+
}) => pt,
507506
UnpackedKind::Lifetime(_) | UnpackedKind::Type(_) => {
508507
// not a type or region param - this should be reported
509508
// as an error.
510509
return false;
511510
}
512511
};
513-
!impl_generics.param_at(index, self).pure_wrt_drop
512+
!impl_generics.param_at(param.index, self).pure_wrt_drop
514513
}).map(|(&item_param, _)| item_param).collect();
515514
debug!("destructor_constraint({:?}) = {:?}", def.did, result);
516515
result

src/librustc/util/ppaux.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -805,7 +805,7 @@ define_print! {
805805
// `explain_region()` or `note_and_explain_region()`.
806806
match *self {
807807
ty::ReEarlyBound(ref data) => {
808-
write!(f, "{}", ty::tls::with(|tcx| tcx.generic_param_name(data.def_id)))
808+
print!(f, cx, print_display(data))
809809
}
810810
ty::ReCanonical(_) => {
811811
write!(f, "'_")
@@ -846,9 +846,7 @@ define_print! {
846846
debug {
847847
match *self {
848848
ty::ReEarlyBound(ref data) => {
849-
write!(f, "ReEarlyBound({}, {})",
850-
data.index,
851-
ty::tls::with(|tcx| tcx.generic_param_name(data.def_id)))
849+
print!(f, cx, print_debug(data))
852850
}
853851

854852
ty::ReClosureBound(ref vid) => {
@@ -1311,12 +1309,13 @@ define_print! {
13111309
}
13121310

13131311
define_print! {
1314-
() ty::ParamTy, (self, f, cx) {
1312+
() ty::GenericParam, (self, f, cx) {
13151313
display {
13161314
write!(f, "{}", ty::tls::with(|tcx| tcx.generic_param_name(self.def_id)))
13171315
}
13181316
debug {
1319-
write!(f, "{}/#{}", ty::tls::with(|tcx| tcx.generic_param_name(self.def_id)), self.idx)
1317+
write!(f, "{}/#{}",
1318+
ty::tls::with(|tcx| tcx.generic_param_name(self.def_id)), self.index)
13201319
}
13211320
}
13221321
}

src/librustc_driver/test.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -313,15 +313,15 @@ impl<'a, 'gcx, 'tcx> Env<'a, 'gcx, 'tcx> {
313313

314314
pub fn t_param(&self, index: u32) -> Ty<'tcx> {
315315
let def_id = self.infcx.tcx.hir.local_def_id(ast::CRATE_NODE_ID);
316-
self.infcx.tcx.mk_ty(ty::TyParam(ty::ParamTy {
316+
self.infcx.tcx.mk_ty(ty::TyParam(ty::GenericParam {
317317
idx: index,
318318
def_id,
319319
}))
320320
}
321321

322322
pub fn re_early_bound(&self, index: u32, name: &'static str) -> ty::Region<'tcx> {
323323
let name = Symbol::intern(name).as_interned_str();
324-
self.infcx.tcx.mk_region(ty::ReEarlyBound(ty::EarlyBoundRegion {
324+
self.infcx.tcx.mk_region(ty::ReEarlyBound(ty::GenericParam {
325325
def_id: self.infcx.tcx.hir.local_def_id(ast::CRATE_NODE_ID),
326326
index,
327327
name,

src/librustc_typeck/astconv.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx>+'o {
133133
}
134134

135135
Some(rl::Region::EarlyBound(index, id, _)) => {
136-
tcx.mk_region(ty::ReEarlyBound(ty::EarlyBoundRegion {
136+
tcx.mk_region(ty::ReEarlyBound(ty::GenericParam {
137137
def_id: id,
138138
index,
139139
}))

src/librustc_typeck/check/cast.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ enum PointerKind<'tcx> {
8181
/// The unsize info of this anon ty
8282
OfAnon(DefId, &'tcx Substs<'tcx>),
8383
/// The unsize info of this parameter
84-
OfParam(&'tcx ty::ParamTy),
84+
OfParam(&'tcx ty::GenericParam),
8585
}
8686

8787
impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {

src/librustc_typeck/check/method/probe.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,7 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
642642

643643
fn assemble_inherent_candidates_from_param(&mut self,
644644
_rcvr_ty: Ty<'tcx>,
645-
param_ty: ty::ParamTy) {
645+
param_ty: ty::GenericParam) {
646646
// FIXME -- Do we want to commit to this behavior for param bounds?
647647

648648
let bounds: Vec<_> = self.param_env

src/librustc_typeck/check/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -5242,9 +5242,9 @@ pub fn check_bounds_are_used<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
52425242
let mut types_used = vec![false; own_counts.types];
52435243

52445244
for leaf_ty in ty.walk() {
5245-
if let ty::Param(ty::ParamTy { idx, .. }) = leaf_ty.sty {
5246-
debug!("Found use of ty param num {}", idx);
5247-
types_used[idx as usize - own_counts.lifetimes] = true;
5245+
if let ty::Param(ref p) = leaf_ty.sty {
5246+
debug!("Found use of ty param num {}", p.index);
5247+
types_used[p.index as usize - own_counts.lifetimes] = true;
52485248
} else if let ty::Error = leaf_ty.sty {
52495249
// If there is already another error, do not emit
52505250
// an error for not using a type Parameter.

src/librustc_typeck/check/wfcheck.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ fn check_where_clauses<'a, 'gcx, 'fcx, 'tcx>(
455455
fn visit_ty(&mut self, t: Ty<'tcx>) -> bool {
456456
match t.sty {
457457
ty::Param(p) => {
458-
self.params.insert(p.idx);
458+
self.params.insert(p.index);
459459
t.super_visit_with(self)
460460
}
461461
_ => t.super_visit_with(self)

src/librustc_typeck/check/writeback.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ impl<'cx, 'gcx, 'tcx> WritebackCx<'cx, 'gcx, 'tcx> {
463463
if subst == region {
464464
// found it in the substitution list, replace with the
465465
// parameter from the existential type
466-
let reg = ty::EarlyBoundRegion {
466+
let reg = ty::GenericParam {
467467
def_id: p.def_id,
468468
index: p.index,
469469
};

src/librustc_typeck/collect.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1740,7 +1740,7 @@ fn explicit_predicates_of<'a, 'tcx>(
17401740
// have to be careful to only iterate over early-bound regions.
17411741
let mut index = parent_count + has_own_self as u32;
17421742
for param in early_bound_lifetimes_from_generics(tcx, ast_generics) {
1743-
let region = tcx.mk_region(ty::ReEarlyBound(ty::EarlyBoundRegion {
1743+
let region = tcx.mk_region(ty::ReEarlyBound(ty::GenericParam {
17441744
def_id: tcx.hir.local_def_id(param.id),
17451745
index,
17461746
}));

0 commit comments

Comments
 (0)