Skip to content

Commit 1fe6160

Browse files
committed
Fix ICE with impl Trait in type bounds
1 parent 3620456 commit 1fe6160

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

src/librustdoc/clean/mod.rs

+10-3
Original file line numberDiff line numberDiff line change
@@ -1725,7 +1725,7 @@ impl<'a, 'tcx> Clean<Generics> for (&'a ty::Generics,
17251725
let mut impl_trait_proj =
17261726
FxHashMap::<u32, Vec<(DefId, String, Ty<'tcx>)>>::default();
17271727

1728-
let mut where_predicates = preds.predicates.iter()
1728+
let where_predicates = preds.predicates.iter()
17291729
.flat_map(|(p, _)| {
17301730
let mut projection = None;
17311731
let param_idx = (|| {
@@ -1747,10 +1747,10 @@ impl<'a, 'tcx> Clean<Generics> for (&'a ty::Generics,
17471747
None
17481748
})();
17491749

1750-
let p = p.clean(cx)?;
1751-
17521750
if let Some(param_idx) = param_idx {
17531751
if let Some(b) = impl_trait.get_mut(&param_idx.into()) {
1752+
let p = p.clean(cx)?;
1753+
17541754
b.extend(
17551755
p.get_bounds()
17561756
.into_iter()
@@ -1805,6 +1805,13 @@ impl<'a, 'tcx> Clean<Generics> for (&'a ty::Generics,
18051805
cx.impl_trait_bounds.borrow_mut().insert(param, bounds);
18061806
}
18071807

1808+
// Now that `cx.impl_trait_bounds` is populated, we can process
1809+
// remaining predicates which could contain `impl Trait`.
1810+
let mut where_predicates = where_predicates
1811+
.into_iter()
1812+
.flat_map(|p| p.clean(cx))
1813+
.collect::<Vec<_>>();
1814+
18081815
// Type parameters and have a Sized bound by default unless removed with
18091816
// ?Sized. Scan through the predicates and mark any type parameter with
18101817
// a Sized bound, removing the bounds as we find them.

src/test/rustdoc/inline_cross/auxiliary/impl_trait_aux.rs

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ pub fn func2<T>(
99

1010
pub fn func3(_x: impl Iterator<Item = impl Iterator<Item = u8>> + Clone) {}
1111

12+
pub fn func4<T: Iterator<Item = impl Clone>>(_x: T) {}
13+
1214
pub struct Foo;
1315

1416
impl Foo {

src/test/rustdoc/inline_cross/impl_trait.rs

+6
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ pub use impl_trait_aux::func2;
2020
// @!has - '//pre[@class="rust fn"]' 'where'
2121
pub use impl_trait_aux::func3;
2222

23+
24+
// @has impl_trait/fn.func4.html
25+
// @has - '//pre[@class="rust fn"]' "func4<T>("
26+
// @has - '//pre[@class="rust fn"]' "T: Iterator<Item = impl Clone>,"
27+
pub use impl_trait_aux::func4;
28+
2329
// @has impl_trait/struct.Foo.html
2430
// @has - '//code[@id="method.v"]' "pub fn method<'a>(_x: impl Clone + Into<Vec<u8>> + 'a)"
2531
// @!has - '//code[@id="method.v"]' 'where'

0 commit comments

Comments
 (0)