From 1fe6160c7e4b584795c66f21683064f62803acf0 Mon Sep 17 00:00:00 2001 From: Shotaro Yamada Date: Tue, 9 Jul 2019 16:59:34 +0900 Subject: [PATCH] Fix ICE with `impl Trait` in type bounds --- src/librustdoc/clean/mod.rs | 13 ++++++++++--- .../inline_cross/auxiliary/impl_trait_aux.rs | 2 ++ src/test/rustdoc/inline_cross/impl_trait.rs | 6 ++++++ 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 37ee79aa9e4f1..ba792a413b3c4 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -1725,7 +1725,7 @@ impl<'a, 'tcx> Clean for (&'a ty::Generics, let mut impl_trait_proj = FxHashMap::)>>::default(); - let mut where_predicates = preds.predicates.iter() + let where_predicates = preds.predicates.iter() .flat_map(|(p, _)| { let mut projection = None; let param_idx = (|| { @@ -1747,10 +1747,10 @@ impl<'a, 'tcx> Clean for (&'a ty::Generics, None })(); - let p = p.clean(cx)?; - if let Some(param_idx) = param_idx { if let Some(b) = impl_trait.get_mut(¶m_idx.into()) { + let p = p.clean(cx)?; + b.extend( p.get_bounds() .into_iter() @@ -1805,6 +1805,13 @@ impl<'a, 'tcx> Clean for (&'a ty::Generics, cx.impl_trait_bounds.borrow_mut().insert(param, bounds); } + // Now that `cx.impl_trait_bounds` is populated, we can process + // remaining predicates which could contain `impl Trait`. + let mut where_predicates = where_predicates + .into_iter() + .flat_map(|p| p.clean(cx)) + .collect::>(); + // Type parameters and have a Sized bound by default unless removed with // ?Sized. Scan through the predicates and mark any type parameter with // a Sized bound, removing the bounds as we find them. diff --git a/src/test/rustdoc/inline_cross/auxiliary/impl_trait_aux.rs b/src/test/rustdoc/inline_cross/auxiliary/impl_trait_aux.rs index 24efe4297103f..21c733a9bc98e 100644 --- a/src/test/rustdoc/inline_cross/auxiliary/impl_trait_aux.rs +++ b/src/test/rustdoc/inline_cross/auxiliary/impl_trait_aux.rs @@ -9,6 +9,8 @@ pub fn func2( pub fn func3(_x: impl Iterator> + Clone) {} +pub fn func4>(_x: T) {} + pub struct Foo; impl Foo { diff --git a/src/test/rustdoc/inline_cross/impl_trait.rs b/src/test/rustdoc/inline_cross/impl_trait.rs index 3a9f2f880798d..b1e3f8d145b5f 100644 --- a/src/test/rustdoc/inline_cross/impl_trait.rs +++ b/src/test/rustdoc/inline_cross/impl_trait.rs @@ -20,6 +20,12 @@ pub use impl_trait_aux::func2; // @!has - '//pre[@class="rust fn"]' 'where' pub use impl_trait_aux::func3; + +// @has impl_trait/fn.func4.html +// @has - '//pre[@class="rust fn"]' "func4(" +// @has - '//pre[@class="rust fn"]' "T: Iterator," +pub use impl_trait_aux::func4; + // @has impl_trait/struct.Foo.html // @has - '//code[@id="method.v"]' "pub fn method<'a>(_x: impl Clone + Into> + 'a)" // @!has - '//code[@id="method.v"]' 'where'