Skip to content

Commit

Permalink
Auto merge of rust-lang#63937 - Nashenas88:rustdoc_57180, r=Guillaume…
Browse files Browse the repository at this point in the history
…Gomez

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

Fixes rust-lang#57180
  • Loading branch information
bors committed Sep 27, 2019
2 parents 590ae0e + 143b83a commit a37fe2d
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 17 deletions.
25 changes: 8 additions & 17 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 @@ -122,9 +117,9 @@ pub fn merge_bounds(
},
});
}
PP::Parenthesized { ref mut output, .. } => {
assert!(output.is_none());
if *rhs != clean::Type::Tuple(Vec::new()) {
PP::Parenthesized { ref mut output, .. } => match output {
Some(o) => assert_eq!(o, rhs),
None => if *rhs != clean::Type::Tuple(Vec::new()) {
*output = Some(rhs.clone());
}
}
Expand All @@ -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
16 changes: 16 additions & 0 deletions src/test/rustdoc/auxiliary/issue-57180.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// compile-flags: -Cmetadata=aux

pub trait Trait {
}

pub struct Struct<F>
{
_p: ::std::marker::PhantomData<F>,
}

impl<F: Fn() -> u32>
Trait for Struct<F>
where
F: Fn() -> u32,
{
}
7 changes: 7 additions & 0 deletions src/test/rustdoc/issue-57180.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// aux-build:issue-57180.rs

extern crate issue_57180;
use issue_57180::Trait;

fn main() {
}

0 comments on commit a37fe2d

Please sign in to comment.