Skip to content

Commit 73f6210

Browse files
committed
rustc: move TypeParamDef's fields into GenericParamDefKind::Type.
1 parent ba2c5c5 commit 73f6210

File tree

25 files changed

+94
-91
lines changed

25 files changed

+94
-91
lines changed

src/librustc/ich/impls_ty.rs

+20-12
Original file line numberDiff line numberDiff line change
@@ -739,8 +739,7 @@ impl<'a> HashStable<StableHashingContext<'a>> for ty::Generics {
739739
ref parent_count,
740740
ref params,
741741

742-
// Reverse map to each `TypeParamDef`'s `index` field, from
743-
// `def_id.index` (`def_id.krate` is the same as the item's).
742+
// Reverse map to each param's `index` field, from its `def_id`.
744743
param_def_id_to_index: _, // Don't hash this
745744
has_self,
746745
has_late_bound_regions,
@@ -754,11 +753,6 @@ impl<'a> HashStable<StableHashingContext<'a>> for ty::Generics {
754753
}
755754
}
756755

757-
impl_stable_hash_for!(enum ty::GenericParamDefKind {
758-
Lifetime,
759-
Type(ty)
760-
});
761-
762756
impl_stable_hash_for!(struct ty::GenericParamDef {
763757
name,
764758
def_id,
@@ -767,11 +761,25 @@ impl_stable_hash_for!(struct ty::GenericParamDef {
767761
kind
768762
});
769763

770-
impl_stable_hash_for!(struct ty::TypeParamDef {
771-
has_default,
772-
object_lifetime_default,
773-
synthetic
774-
});
764+
impl<'a> HashStable<StableHashingContext<'a>> for ty::GenericParamDefKind {
765+
fn hash_stable<W: StableHasherResult>(&self,
766+
hcx: &mut StableHashingContext<'a>,
767+
hasher: &mut StableHasher<W>) {
768+
mem::discriminant(self).hash_stable(hcx, hasher);
769+
match *self {
770+
ty::GenericParamDefKind::Lifetime => {}
771+
ty::GenericParamDefKind::Type {
772+
has_default,
773+
ref object_lifetime_default,
774+
ref synthetic,
775+
} => {
776+
has_default.hash_stable(hcx, hasher);
777+
object_lifetime_default.hash_stable(hcx, hasher);
778+
synthetic.hash_stable(hcx, hasher);
779+
}
780+
}
781+
}
782+
}
775783

776784
impl<'a, 'gcx, T> HashStable<StableHashingContext<'a>>
777785
for ::middle::resolve_lifetime::Set1<T>

src/librustc/infer/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -915,7 +915,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
915915
// region parameter definition.
916916
self.next_region_var(EarlyBoundRegion(span, param.name)).into()
917917
}
918-
GenericParamDefKind::Type(_) => {
918+
GenericParamDefKind::Type {..} => {
919919
// Create a type inference variable for the given
920920
// type parameter definition. The substitutions are
921921
// for actual parameters that may be referred to by

src/librustc/middle/resolve_lifetime.rs

+7-11
Original file line numberDiff line numberDiff line change
@@ -1658,18 +1658,14 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
16581658
self.xcrate_object_lifetime_defaults
16591659
.entry(def_id)
16601660
.or_insert_with(|| {
1661-
tcx.generics_of(def_id)
1662-
.params
1663-
.iter()
1664-
.filter_map(|param| {
1665-
match param.kind {
1666-
GenericParamDefKind::Type(ty) => {
1667-
Some(ty.object_lifetime_default)
1668-
}
1669-
GenericParamDefKind::Lifetime => None,
1661+
tcx.generics_of(def_id).params.iter().filter_map(|param| {
1662+
match param.kind {
1663+
GenericParamDefKind::Type { object_lifetime_default, .. } => {
1664+
Some(object_lifetime_default)
16701665
}
1671-
})
1672-
.collect()
1666+
GenericParamDefKind::Lifetime => None,
1667+
}
1668+
}).collect()
16731669
})
16741670
};
16751671
unsubst

src/librustc/traits/error_reporting.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
383383

384384
for param in generics.params.iter() {
385385
let value = match param.kind {
386-
GenericParamDefKind::Type(_) => {
386+
GenericParamDefKind::Type {..} => {
387387
trait_ref.substs[param.index as usize].to_string()
388388
},
389389
GenericParamDefKind::Lifetime => continue,

src/librustc/traits/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -838,7 +838,7 @@ fn vtable_methods<'a, 'tcx>(
838838
Substs::for_item(tcx, def_id, |param, _| {
839839
match param.kind {
840840
GenericParamDefKind::Lifetime => tcx.types.re_erased.into(),
841-
GenericParamDefKind::Type(_) => {
841+
GenericParamDefKind::Type {..} => {
842842
trait_ref.substs[param.index as usize]
843843
}
844844
}

src/librustc/traits/on_unimplemented.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ impl<'a, 'gcx, 'tcx> OnUnimplementedFormatString {
289289
let generics = tcx.generics_of(trait_ref.def_id);
290290
let generic_map = generics.params.iter().filter_map(|param| {
291291
let value = match param.kind {
292-
GenericParamDefKind::Type(_) => {
292+
GenericParamDefKind::Type {..} => {
293293
trait_ref.substs[param.index as usize].to_string()
294294
},
295295
GenericParamDefKind::Lifetime => return None

src/librustc/ty/context.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -2329,11 +2329,11 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
23292329
let substs = Substs::for_item(self, def_id, |param, substs| {
23302330
match param.kind {
23312331
GenericParamDefKind::Lifetime => bug!(),
2332-
GenericParamDefKind::Type(ty_param) => {
2332+
GenericParamDefKind::Type { has_default, .. } => {
23332333
if param.index == 0 {
23342334
ty.into()
23352335
} else {
2336-
assert!(ty_param.has_default);
2336+
assert!(has_default);
23372337
self.type_of(param.def_id).subst(self, substs).into()
23382338
}
23392339
}
@@ -2477,7 +2477,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
24772477
GenericParamDefKind::Lifetime => {
24782478
self.mk_region(ty::ReEarlyBound(param.to_early_bound_region_data())).into()
24792479
}
2480-
GenericParamDefKind::Type(_) => self.mk_ty_param(param.index, param.name).into(),
2480+
GenericParamDefKind::Type {..} => self.mk_ty_param(param.index, param.name).into(),
24812481
}
24822482
}
24832483

src/librustc/ty/mod.rs

+9-12
Original file line numberDiff line numberDiff line change
@@ -714,13 +714,6 @@ pub enum IntVarValue {
714714
#[derive(Clone, Copy, PartialEq, Eq)]
715715
pub struct FloatVarValue(pub ast::FloatTy);
716716

717-
#[derive(Copy, Clone, Debug, RustcEncodable, RustcDecodable)]
718-
pub struct TypeParamDef {
719-
pub has_default: bool,
720-
pub object_lifetime_default: ObjectLifetimeDefault,
721-
pub synthetic: Option<hir::SyntheticTyParamKind>,
722-
}
723-
724717
impl ty::EarlyBoundRegion {
725718
pub fn to_bound_region(&self) -> ty::BoundRegion {
726719
ty::BoundRegion::BrNamed(self.def_id, self.name)
@@ -730,7 +723,11 @@ impl ty::EarlyBoundRegion {
730723
#[derive(Clone, Debug, RustcEncodable, RustcDecodable)]
731724
pub enum GenericParamDefKind {
732725
Lifetime,
733-
Type(TypeParamDef),
726+
Type {
727+
has_default: bool,
728+
object_lifetime_default: ObjectLifetimeDefault,
729+
synthetic: Option<hir::SyntheticTyParamKind>,
730+
}
734731
}
735732

736733
#[derive(Clone, RustcEncodable, RustcDecodable)]
@@ -811,7 +808,7 @@ impl<'a, 'gcx, 'tcx> Generics {
811808
for param in &self.params {
812809
match param.kind {
813810
GenericParamDefKind::Lifetime => own_counts.lifetimes += 1,
814-
GenericParamDefKind::Type(_) => own_counts.types += 1,
811+
GenericParamDefKind::Type {..} => own_counts.types += 1,
815812
};
816813
}
817814

@@ -821,7 +818,7 @@ impl<'a, 'gcx, 'tcx> Generics {
821818
pub fn requires_monomorphization(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> bool {
822819
for param in &self.params {
823820
match param.kind {
824-
GenericParamDefKind::Type(_) => return true,
821+
GenericParamDefKind::Type {..} => return true,
825822
GenericParamDefKind::Lifetime => {}
826823
}
827824
}
@@ -850,15 +847,15 @@ impl<'a, 'gcx, 'tcx> Generics {
850847
}
851848
}
852849

853-
/// Returns the `TypeParamDef` associated with this `ParamTy`.
850+
/// Returns the `GenericParamDef` associated with this `ParamTy`.
854851
pub fn type_param(&'tcx self,
855852
param: &ParamTy,
856853
tcx: TyCtxt<'a, 'gcx, 'tcx>)
857854
-> &'tcx GenericParamDef {
858855
if let Some(index) = param.idx.checked_sub(self.parent_count as u32) {
859856
let param = &self.params[index as usize];
860857
match param.kind {
861-
ty::GenericParamDefKind::Type(_) => param,
858+
ty::GenericParamDefKind::Type {..} => param,
862859
_ => bug!("expected type parameter, but found another generic parameter")
863860
}
864861
} else {

src/librustc/ty/util.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
572572
Substs::for_item(self, item_def_id, |param, _| {
573573
match param.kind {
574574
GenericParamDefKind::Lifetime => self.types.re_erased.into(),
575-
GenericParamDefKind::Type(_) => {
575+
GenericParamDefKind::Type {..} => {
576576
bug!("empty_substs_for_def_id: {:?} has type parameters", item_def_id)
577577
}
578578
}

src/librustc/util/ppaux.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,9 @@ impl PrintContext {
337337
let mut type_params =
338338
generics.params.iter().rev().filter_map(|param| {
339339
match param.kind {
340-
GenericParamDefKind::Type(ty) => Some((param.def_id, ty.has_default)),
340+
GenericParamDefKind::Type { has_default, .. } => {
341+
Some((param.def_id, has_default))
342+
}
341343
GenericParamDefKind::Lifetime => None,
342344
}
343345
}).peekable();
@@ -604,7 +606,7 @@ impl fmt::Debug for ty::GenericParamDef {
604606
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
605607
let type_name = match self.kind {
606608
ty::GenericParamDefKind::Lifetime => "Lifetime",
607-
ty::GenericParamDefKind::Type(_) => "Type",
609+
ty::GenericParamDefKind::Type {..} => "Type",
608610
};
609611
write!(f, "{}({}, {:?}, {})",
610612
type_name,

src/librustc_mir/monomorphize/collector.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1115,7 +1115,7 @@ fn create_mono_items_for_default_impls<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
11151115
let substs = Substs::for_item(tcx, method.def_id, |param, _| {
11161116
match param.kind {
11171117
GenericParamDefKind::Lifetime => tcx.types.re_erased.into(),
1118-
GenericParamDefKind::Type(_) => {
1118+
GenericParamDefKind::Type {..} => {
11191119
trait_ref.substs[param.index as usize]
11201120
}
11211121
}

src/librustc_mir/shim.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ impl<'a, 'tcx> CloneShimBuilder<'a, 'tcx> {
430430
let substs = Substs::for_item(tcx, self.def_id, |param, _| {
431431
match param.kind {
432432
GenericParamDefKind::Lifetime => tcx.types.re_erased.into(),
433-
GenericParamDefKind::Type(_) => ty.into(),
433+
GenericParamDefKind::Type {..} => ty.into(),
434434
}
435435
});
436436

src/librustc_privacy/lib.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -401,8 +401,8 @@ impl<'b, 'a, 'tcx> ReachEverythingInTheInterfaceVisitor<'b, 'a, 'tcx> {
401401
fn generics(&mut self) -> &mut Self {
402402
for param in &self.ev.tcx.generics_of(self.item_def_id).params {
403403
match param.kind {
404-
GenericParamDefKind::Type(ty) => {
405-
if ty.has_default {
404+
GenericParamDefKind::Type { has_default, .. } => {
405+
if has_default {
406406
self.ev.tcx.type_of(param.def_id).visit_with(self);
407407
}
408408
}
@@ -1342,8 +1342,8 @@ impl<'a, 'tcx: 'a> SearchInterfaceForPrivateItemsVisitor<'a, 'tcx> {
13421342
fn generics(&mut self) -> &mut Self {
13431343
for param in &self.tcx.generics_of(self.item_def_id).params {
13441344
match param.kind {
1345-
GenericParamDefKind::Type(ty) => {
1346-
if ty.has_default {
1345+
GenericParamDefKind::Type { has_default, .. } => {
1346+
if has_default {
13471347
self.tcx.type_of(param.def_id).visit_with(self);
13481348
}
13491349
}

src/librustc_typeck/astconv.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -224,9 +224,9 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
224224
GenericParamDefKind::Lifetime => {
225225
lt_accepted += 1;
226226
}
227-
GenericParamDefKind::Type(ty) => {
227+
GenericParamDefKind::Type { has_default, .. } => {
228228
ty_params.accepted += 1;
229-
if !ty.has_default {
229+
if !has_default {
230230
ty_params.required += 1;
231231
}
232232
}
@@ -251,8 +251,8 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
251251

252252
let is_object = self_ty.map_or(false, |ty| ty.sty == TRAIT_OBJECT_DUMMY_SELF);
253253
let default_needs_object_self = |param: &ty::GenericParamDef| {
254-
if let GenericParamDefKind::Type(ty) = param.kind {
255-
if is_object && ty.has_default {
254+
if let GenericParamDefKind::Type { has_default, .. } = param.kind {
255+
if is_object && has_default {
256256
if tcx.at(span).type_of(param.def_id).has_self_ty() {
257257
// There is no suitable inference default for a type parameter
258258
// that references self, in an object type.
@@ -275,7 +275,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
275275
tcx.types.re_static.into()
276276
}
277277
}
278-
GenericParamDefKind::Type(ty) => {
278+
GenericParamDefKind::Type { has_default, .. } => {
279279
let i = param.index as usize;
280280

281281
// Handle Self first, so we can adjust the index to match the AST.
@@ -294,7 +294,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
294294
} else {
295295
self.ty_infer(span).into()
296296
}
297-
} else if ty.has_default {
297+
} else if has_default {
298298
// No type parameter provided, but a default exists.
299299

300300
// If we are converting an object type, then the

src/librustc_typeck/check/closure.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
109109
GenericParamDefKind::Lifetime => {
110110
span_bug!(expr.span, "closure has region param")
111111
}
112-
GenericParamDefKind::Type(_) => {
112+
GenericParamDefKind::Type {..} => {
113113
self.infcx
114114
.next_ty_var(TypeVariableOrigin::ClosureSynthetic(expr.span)).into()
115115
}

src/librustc_typeck/check/compare_method.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -730,13 +730,13 @@ fn compare_synthetic_generics<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
730730
let trait_m_generics = tcx.generics_of(trait_m.def_id);
731731
let impl_m_type_params = impl_m_generics.params.iter().filter_map(|param| {
732732
match param.kind {
733-
GenericParamDefKind::Type(ty) => Some((param.def_id, ty.synthetic)),
733+
GenericParamDefKind::Type { synthetic, .. } => Some((param.def_id, synthetic)),
734734
GenericParamDefKind::Lifetime => None,
735735
}
736736
});
737737
let trait_m_type_params = trait_m_generics.params.iter().filter_map(|param| {
738738
match param.kind {
739-
GenericParamDefKind::Type(ty) => Some((param.def_id, ty.synthetic)),
739+
GenericParamDefKind::Type { synthetic, .. } => Some((param.def_id, synthetic)),
740740
GenericParamDefKind::Lifetime => None,
741741
}
742742
});

src/librustc_typeck/check/method/confirm.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ impl<'a, 'gcx, 'tcx> ConfirmContext<'a, 'gcx, 'tcx> {
331331
self.fcx, lifetime, Some(param)).into();
332332
}
333333
}
334-
GenericParamDefKind::Type(_) => {
334+
GenericParamDefKind::Type {..} => {
335335
if let Some(ast_ty) = provided.as_ref().and_then(|p| {
336336
p.types.get(i - parent_substs.len() - own_counts.lifetimes)
337337
}) {

src/librustc_typeck/check/method/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
257257
let substs = Substs::for_item(self.tcx, trait_def_id, |param, _| {
258258
match param.kind {
259259
GenericParamDefKind::Lifetime => {}
260-
GenericParamDefKind::Type(_) => {
260+
GenericParamDefKind::Type {..} => {
261261
if param.index == 0 {
262262
return self_ty.into();
263263
} else if let Some(ref input_types) = opt_input_types {

src/librustc_typeck/check/method/probe.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1399,7 +1399,7 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
13991399
// `impl_self_ty()` for an explanation.
14001400
self.tcx.types.re_erased.into()
14011401
}
1402-
GenericParamDefKind::Type(_) => self.var_for_def(self.span, param),
1402+
GenericParamDefKind::Type {..} => self.var_for_def(self.span, param),
14031403
}
14041404
}
14051405
});
@@ -1416,7 +1416,7 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
14161416
Substs::for_item(self.tcx, def_id, |param, _| {
14171417
match param.kind {
14181418
GenericParamDefKind::Lifetime => self.tcx.types.re_erased.into(),
1419-
GenericParamDefKind::Type(_) => {
1419+
GenericParamDefKind::Type {..} => {
14201420
self.next_ty_var(TypeVariableOrigin::SubstitutionPlaceholder(
14211421
self.tcx.def_span(def_id))).into()
14221422
}

0 commit comments

Comments
 (0)