Skip to content

Commit

Permalink
Fix ICE with impl Trait in type bounds
Browse files Browse the repository at this point in the history
  • Loading branch information
sinkuu committed Aug 19, 2019
1 parent 3620456 commit 1fe6160
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1725,7 +1725,7 @@ impl<'a, 'tcx> Clean<Generics> for (&'a ty::Generics,
let mut impl_trait_proj =
FxHashMap::<u32, Vec<(DefId, String, Ty<'tcx>)>>::default();

let mut where_predicates = preds.predicates.iter()
let where_predicates = preds.predicates.iter()
.flat_map(|(p, _)| {
let mut projection = None;
let param_idx = (|| {
Expand All @@ -1747,10 +1747,10 @@ impl<'a, 'tcx> Clean<Generics> 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(&param_idx.into()) {
let p = p.clean(cx)?;

b.extend(
p.get_bounds()
.into_iter()
Expand Down Expand Up @@ -1805,6 +1805,13 @@ impl<'a, 'tcx> Clean<Generics> 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::<Vec<_>>();

// 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.
Expand Down
2 changes: 2 additions & 0 deletions src/test/rustdoc/inline_cross/auxiliary/impl_trait_aux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ pub fn func2<T>(

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

pub fn func4<T: Iterator<Item = impl Clone>>(_x: T) {}

pub struct Foo;

impl Foo {
Expand Down
6 changes: 6 additions & 0 deletions src/test/rustdoc/inline_cross/impl_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>("
// @has - '//pre[@class="rust fn"]' "T: Iterator<Item = impl Clone>,"
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<Vec<u8>> + 'a)"
// @!has - '//code[@id="method.v"]' 'where'
Expand Down

0 comments on commit 1fe6160

Please sign in to comment.