Skip to content

Commit b3e001b

Browse files
committed
rustc: unify Generics::{region,type}_param.
1 parent 79068b7 commit b3e001b

File tree

2 files changed

+11
-38
lines changed

2 files changed

+11
-38
lines changed

src/librustc/ty/mod.rs

Lines changed: 4 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -939,37 +939,12 @@ impl<'a, 'gcx, 'tcx> Generics {
939939
}
940940
}
941941

942-
pub fn region_param(&'tcx self,
943-
param: &EarlyBoundRegion,
944-
tcx: TyCtxt<'a, 'gcx, 'tcx>)
945-
-> &'tcx GenericParamDef
946-
{
947-
if let Some(index) = param.index.checked_sub(self.parent_count as u32) {
948-
let param = &self.params[index as usize];
949-
match param.kind {
950-
ty::GenericParamDefKind::Lifetime => param,
951-
_ => bug!("expected lifetime parameter, but found another generic parameter")
952-
}
953-
} else {
954-
tcx.generics_of(self.parent.expect("parent_count>0 but no parent?"))
955-
.region_param(param, tcx)
956-
}
957-
}
958-
959-
/// Returns the `GenericParamDef` associated with this `ParamTy`.
960-
pub fn type_param(&'tcx self,
961-
param: &ParamTy,
962-
tcx: TyCtxt<'a, 'gcx, 'tcx>)
963-
-> &'tcx GenericParamDef {
964-
if let Some(index) = param.idx.checked_sub(self.parent_count as u32) {
965-
let param = &self.params[index as usize];
966-
match param.kind {
967-
ty::GenericParamDefKind::Type {..} => param,
968-
_ => bug!("expected type parameter, but found another generic parameter")
969-
}
942+
pub fn param_at(&'tcx self, index: u32, tcx: TyCtxt<'_, '_, 'tcx>) -> &'tcx GenericParamDef {
943+
if let Some(index) = index.checked_sub(self.parent_count as u32) {
944+
&self.params[index as usize]
970945
} else {
971946
tcx.generics_of(self.parent.expect("parent_count>0 but no parent?"))
972-
.type_param(param, tcx)
947+
.param_at(index, tcx)
973948
}
974949
}
975950
}

src/librustc/ty/util.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -498,21 +498,19 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
498498

499499
let result = item_substs.iter().zip(impl_substs.iter())
500500
.filter(|&(_, &k)| {
501-
match k.unpack() {
502-
UnpackedKind::Lifetime(&ty::RegionKind::ReEarlyBound(ref ebr)) => {
503-
!impl_generics.region_param(ebr, self).pure_wrt_drop
504-
}
501+
let index = match k.unpack() {
502+
UnpackedKind::Lifetime(&ty::RegionKind::ReEarlyBound(ref ebr)) =>
503+
ebr.index,
505504
UnpackedKind::Type(&ty::TyS {
506505
sty: ty::Param(ref pt), ..
507-
}) => {
508-
!impl_generics.type_param(pt, self).pure_wrt_drop
509-
}
506+
}) => pt.idx,
510507
UnpackedKind::Lifetime(_) | UnpackedKind::Type(_) => {
511508
// not a type or region param - this should be reported
512509
// as an error.
513-
false
510+
return false;
514511
}
515-
}
512+
};
513+
!impl_generics.param_at(index, self).pure_wrt_drop
516514
}).map(|(&item_param, _)| item_param).collect();
517515
debug!("destructor_constraint({:?}) = {:?}", def.did, result);
518516
result

0 commit comments

Comments
 (0)