Extend substs_to_args
into a perfectly-sized Vec almost every time
This commit is contained in:
parent
08237d8a6d
commit
3657d0936f
1 changed files with 16 additions and 16 deletions
|
@ -80,23 +80,23 @@ pub(crate) fn substs_to_args(
|
||||||
substs: &[ty::subst::GenericArg<'_>],
|
substs: &[ty::subst::GenericArg<'_>],
|
||||||
mut skip_first: bool,
|
mut skip_first: bool,
|
||||||
) -> Vec<GenericArg> {
|
) -> Vec<GenericArg> {
|
||||||
substs
|
let mut ret_val =
|
||||||
.iter()
|
Vec::with_capacity(substs.len().saturating_sub(if skip_first { 1 } else { 0 }));
|
||||||
.filter_map(|kind| match kind.unpack() {
|
ret_val.extend(substs.iter().filter_map(|kind| match kind.unpack() {
|
||||||
GenericArgKind::Lifetime(lt) => match *lt {
|
GenericArgKind::Lifetime(lt) => match *lt {
|
||||||
ty::ReLateBound(_, ty::BoundRegion { kind: ty::BrAnon(_), .. }) => {
|
ty::ReLateBound(_, ty::BoundRegion { kind: ty::BrAnon(_), .. }) => {
|
||||||
Some(GenericArg::Lifetime(Lifetime::elided()))
|
Some(GenericArg::Lifetime(Lifetime::elided()))
|
||||||
}
|
|
||||||
_ => lt.clean(cx).map(GenericArg::Lifetime),
|
|
||||||
},
|
|
||||||
GenericArgKind::Type(_) if skip_first => {
|
|
||||||
skip_first = false;
|
|
||||||
None
|
|
||||||
}
|
}
|
||||||
GenericArgKind::Type(ty) => Some(GenericArg::Type(ty.clean(cx))),
|
_ => lt.clean(cx).map(GenericArg::Lifetime),
|
||||||
GenericArgKind::Const(ct) => Some(GenericArg::Const(Box::new(ct.clean(cx)))),
|
},
|
||||||
})
|
GenericArgKind::Type(_) if skip_first => {
|
||||||
.collect()
|
skip_first = false;
|
||||||
|
None
|
||||||
|
}
|
||||||
|
GenericArgKind::Type(ty) => Some(GenericArg::Type(ty.clean(cx))),
|
||||||
|
GenericArgKind::Const(ct) => Some(GenericArg::Const(Box::new(ct.clean(cx)))),
|
||||||
|
}));
|
||||||
|
ret_val
|
||||||
}
|
}
|
||||||
|
|
||||||
fn external_generic_args(
|
fn external_generic_args(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue