Skip to content

Commit a37fe2d

Browse files
committed
Auto merge of #63937 - Nashenas88:rustdoc_57180, r=GuillaumeGomez
Fix ICE in rustdoc when merging generic and where bounds of an Fn with an output Fixes #57180
2 parents 590ae0e + 143b83a commit a37fe2d

File tree

3 files changed

+31
-17
lines changed

3 files changed

+31
-17
lines changed

src/librustdoc/clean/simplify.rs

+8-17
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ pub fn where_clauses(cx: &DocContext<'_>, clauses: Vec<WP>) -> Vec<WP> {
3535
match ty {
3636
clean::Generic(s) => params.entry(s).or_default()
3737
.extend(bounds),
38-
t => tybounds.push((t, ty_bounds(bounds))),
38+
t => tybounds.push((t, bounds)),
3939
}
4040
}
4141
WP::RegionPredicate { lifetime, bounds } => {
@@ -45,11 +45,6 @@ pub fn where_clauses(cx: &DocContext<'_>, clauses: Vec<WP>) -> Vec<WP> {
4545
}
4646
}
4747

48-
// Simplify the type parameter bounds on all the generics
49-
let mut params = params.into_iter().map(|(k, v)| {
50-
(k, ty_bounds(v))
51-
}).collect::<BTreeMap<_, _>>();
52-
5348
// Look for equality predicates on associated types that can be merged into
5449
// general bound predicates
5550
equalities.retain(|&(ref lhs, ref rhs)| {
@@ -73,7 +68,7 @@ pub fn where_clauses(cx: &DocContext<'_>, clauses: Vec<WP>) -> Vec<WP> {
7368
// And finally, let's reassemble everything
7469
let mut clauses = Vec::new();
7570
clauses.extend(lifetimes.into_iter().map(|(lt, bounds)| {
76-
WP::RegionPredicate { lifetime: lt, bounds: bounds }
71+
WP::RegionPredicate { lifetime: lt, bounds }
7772
}));
7873
clauses.extend(params.into_iter().map(|(k, v)| {
7974
WP::BoundPredicate {
@@ -82,10 +77,10 @@ pub fn where_clauses(cx: &DocContext<'_>, clauses: Vec<WP>) -> Vec<WP> {
8277
}
8378
}));
8479
clauses.extend(tybounds.into_iter().map(|(ty, bounds)| {
85-
WP::BoundPredicate { ty: ty, bounds: bounds }
80+
WP::BoundPredicate { ty, bounds }
8681
}));
8782
clauses.extend(equalities.into_iter().map(|(lhs, rhs)| {
88-
WP::EqPredicate { lhs: lhs, rhs: rhs }
83+
WP::EqPredicate { lhs, rhs }
8984
}));
9085
clauses
9186
}
@@ -122,9 +117,9 @@ pub fn merge_bounds(
122117
},
123118
});
124119
}
125-
PP::Parenthesized { ref mut output, .. } => {
126-
assert!(output.is_none());
127-
if *rhs != clean::Type::Tuple(Vec::new()) {
120+
PP::Parenthesized { ref mut output, .. } => match output {
121+
Some(o) => assert_eq!(o, rhs),
122+
None => if *rhs != clean::Type::Tuple(Vec::new()) {
128123
*output = Some(rhs.clone());
129124
}
130125
}
@@ -137,18 +132,14 @@ pub fn ty_params(mut params: Vec<clean::GenericParamDef>) -> Vec<clean::GenericP
137132
for param in &mut params {
138133
match param.kind {
139134
clean::GenericParamDefKind::Type { ref mut bounds, .. } => {
140-
*bounds = ty_bounds(mem::take(bounds));
135+
*bounds = mem::take(bounds);
141136
}
142137
_ => panic!("expected only type parameters"),
143138
}
144139
}
145140
params
146141
}
147142

148-
fn ty_bounds(bounds: Vec<clean::GenericBound>) -> Vec<clean::GenericBound> {
149-
bounds
150-
}
151-
152143
fn trait_is_same_or_supertrait(cx: &DocContext<'_>, child: DefId,
153144
trait_: DefId) -> bool {
154145
if child == trait_ {
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// compile-flags: -Cmetadata=aux
2+
3+
pub trait Trait {
4+
}
5+
6+
pub struct Struct<F>
7+
{
8+
_p: ::std::marker::PhantomData<F>,
9+
}
10+
11+
impl<F: Fn() -> u32>
12+
Trait for Struct<F>
13+
where
14+
F: Fn() -> u32,
15+
{
16+
}

src/test/rustdoc/issue-57180.rs

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// aux-build:issue-57180.rs
2+
3+
extern crate issue_57180;
4+
use issue_57180::Trait;
5+
6+
fn main() {
7+
}

0 commit comments

Comments
 (0)