Simplify some code in rustdoc's simplify

This commit is contained in:
Paul Daniel Faria 2019-08-27 00:22:31 -04:00
parent c015927af3
commit 09f6b44790

View file

@ -35,7 +35,7 @@ pub fn where_clauses(cx: &DocContext<'_>, clauses: Vec<WP>) -> Vec<WP> {
match ty {
clean::Generic(s) => params.entry(s).or_default()
.extend(bounds),
t => tybounds.push((t, ty_bounds(bounds))),
t => tybounds.push((t, bounds)),
}
}
WP::RegionPredicate { lifetime, bounds } => {
@ -45,11 +45,6 @@ pub fn where_clauses(cx: &DocContext<'_>, clauses: Vec<WP>) -> Vec<WP> {
}
}
// Simplify the type parameter bounds on all the generics
let mut params = params.into_iter().map(|(k, v)| {
(k, ty_bounds(v))
}).collect::<BTreeMap<_, _>>();
// Look for equality predicates on associated types that can be merged into
// general bound predicates
equalities.retain(|&(ref lhs, ref rhs)| {
@ -73,7 +68,7 @@ pub fn where_clauses(cx: &DocContext<'_>, clauses: Vec<WP>) -> Vec<WP> {
// And finally, let's reassemble everything
let mut clauses = Vec::new();
clauses.extend(lifetimes.into_iter().map(|(lt, bounds)| {
WP::RegionPredicate { lifetime: lt, bounds: bounds }
WP::RegionPredicate { lifetime: lt, bounds }
}));
clauses.extend(params.into_iter().map(|(k, v)| {
WP::BoundPredicate {
@ -82,10 +77,10 @@ pub fn where_clauses(cx: &DocContext<'_>, clauses: Vec<WP>) -> Vec<WP> {
}
}));
clauses.extend(tybounds.into_iter().map(|(ty, bounds)| {
WP::BoundPredicate { ty: ty, bounds: bounds }
WP::BoundPredicate { ty, bounds }
}));
clauses.extend(equalities.into_iter().map(|(lhs, rhs)| {
WP::EqPredicate { lhs: lhs, rhs: rhs }
WP::EqPredicate { lhs, rhs }
}));
clauses
}
@ -137,7 +132,7 @@ pub fn ty_params(mut params: Vec<clean::GenericParamDef>) -> Vec<clean::GenericP
for param in &mut params {
match param.kind {
clean::GenericParamDefKind::Type { ref mut bounds, .. } => {
*bounds = ty_bounds(mem::take(bounds));
*bounds = mem::take(bounds);
}
_ => panic!("expected only type parameters"),
}
@ -145,10 +140,6 @@ pub fn ty_params(mut params: Vec<clean::GenericParamDef>) -> Vec<clean::GenericP
params
}
fn ty_bounds(bounds: Vec<clean::GenericBound>) -> Vec<clean::GenericBound> {
bounds
}
fn trait_is_same_or_supertrait(cx: &DocContext<'_>, child: DefId,
trait_: DefId) -> bool {
if child == trait_ {