Inline Generics::own_count
This commit is contained in:
parent
e5825c29c3
commit
5b4e2b7fbc
5 changed files with 12 additions and 16 deletions
|
|
@ -795,12 +795,8 @@ pub struct Generics {
|
|||
}
|
||||
|
||||
impl<'a, 'gcx, 'tcx> Generics {
|
||||
pub fn own_count(&self) -> usize {
|
||||
self.params.len()
|
||||
}
|
||||
|
||||
pub fn count(&self) -> usize {
|
||||
self.parent_count + self.own_count()
|
||||
self.parent_count + self.params.len()
|
||||
}
|
||||
|
||||
pub fn lifetimes(&self) -> impl DoubleEndedIterator<Item = &RegionParameterDef> {
|
||||
|
|
|
|||
|
|
@ -252,20 +252,20 @@ impl<'a, 'gcx, 'tcx> Substs<'tcx> {
|
|||
}
|
||||
|
||||
for def in &defs.params {
|
||||
assert_eq!(def.index() as usize, substs.len());
|
||||
let param = match def {
|
||||
ty::GenericParam::Lifetime(ref lt) => {
|
||||
UnpackedKind::Lifetime(mk_region(lt, substs))
|
||||
mk_region(lt, substs).into()
|
||||
}
|
||||
ty::GenericParam::Type(ref ty) => {
|
||||
if skip_self {
|
||||
skip_self = false;
|
||||
continue
|
||||
}
|
||||
UnpackedKind::Type(mk_type(ty, substs))
|
||||
mk_type(ty, substs).into()
|
||||
}
|
||||
};
|
||||
assert_eq!(def.index() as usize, substs.len());
|
||||
substs.push(param.pack());
|
||||
substs.push(param);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -333,7 +333,7 @@ impl<'a, 'gcx, 'tcx> Substs<'tcx> {
|
|||
target_substs: &Substs<'tcx>)
|
||||
-> &'tcx Substs<'tcx> {
|
||||
let defs = tcx.generics_of(source_ancestor);
|
||||
tcx.mk_substs(target_substs.iter().chain(&self[defs.own_count()..]).cloned())
|
||||
tcx.mk_substs(target_substs.iter().chain(&self[defs.params.len()..]).cloned())
|
||||
}
|
||||
|
||||
pub fn truncate_to(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>, generics: &ty::Generics)
|
||||
|
|
@ -586,7 +586,7 @@ impl<'a, 'gcx, 'tcx> ty::TraitRef<'tcx> {
|
|||
|
||||
ty::TraitRef {
|
||||
def_id: trait_id,
|
||||
substs: tcx.intern_substs(&substs[..defs.own_count()])
|
||||
substs: tcx.intern_substs(&substs[..defs.params.len()])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1143,7 +1143,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
|
|||
assert_eq!(substs.len(), generics.parent_count);
|
||||
|
||||
// Fill in our own generics with the resolved lifetimes
|
||||
assert_eq!(lifetimes.len(), generics.own_count());
|
||||
assert_eq!(lifetimes.len(), generics.params.len());
|
||||
substs.extend(lifetimes.iter().map(|lt| Kind::from(self.ast_region_to_region(lt, None))));
|
||||
|
||||
debug!("impl_trait_ty_to_ty: final substs = {:?}", substs);
|
||||
|
|
|
|||
|
|
@ -4754,7 +4754,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
|||
(generics.parent_count, generics.has_self)
|
||||
}
|
||||
(Some((_, generics)), None) => {
|
||||
(generics.own_count(), generics.has_self)
|
||||
(generics.params.len(), generics.has_self)
|
||||
}
|
||||
(None, None) => (0, false)
|
||||
};
|
||||
|
|
|
|||
|
|
@ -971,10 +971,10 @@ fn generics_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
|||
.collect();
|
||||
|
||||
let lifetimes: Vec<ty::GenericParam> =
|
||||
regions.into_iter().map(|lt| ty::GenericParam::Lifetime(lt)).collect();
|
||||
regions.into_iter().map(|lt| ty::GenericParam::Lifetime(lt));
|
||||
let types: Vec<ty::GenericParam> =
|
||||
types.into_iter().map(|ty| ty::GenericParam::Type(ty)).collect();
|
||||
let params = lifetimes.into_iter().chain(types.into_iter()).collect();
|
||||
types.into_iter().map(|ty| ty::GenericParam::Type(ty));
|
||||
let params = lifetimes.chain(types).collect();
|
||||
|
||||
tcx.alloc_generics(ty::Generics {
|
||||
parent: parent_def_id,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue