Skip to content

Commit

Permalink
Simplify some code in rustdoc's simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
Nashenas88 committed Aug 27, 2019
1 parent c015927 commit 09f6b44
Showing 1 changed file with 5 additions and 14 deletions.
19 changes: 5 additions & 14 deletions src/librustdoc/clean/simplify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 } => {
Expand All @@ -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)| {
Expand All @@ -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 {
Expand All @@ -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
}
Expand Down Expand Up @@ -137,18 +132,14 @@ 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"),
}
}
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_ {
Expand Down

0 comments on commit 09f6b44

Please sign in to comment.