Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ICE in rustdoc when merging generic and where bounds of an Fn with an output #63937

Merged
merged 3 commits into from
Sep 27, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since ty_bounds was a nop, just a pass-through, this transform seemed to just be added noise and should be safe to remove.

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> {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seemed like pointless noise, so I removed it. If this was setup for future work, let me know so I can add a comment explaining that for future readers 😃

bounds
}

fn trait_is_same_or_supertrait(cx: &DocContext<'_>, child: DefId,
trait_: DefId) -> bool {
if child == trait_ {
Expand Down