Skip to content

Commit

Permalink
Avoid ICE in rustdoc.
Browse files Browse the repository at this point in the history
  • Loading branch information
cjgillot authored and Mark-Simulacrum committed Aug 8, 2022
1 parent 903561f commit 7c45c50
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/librustdoc/clean/auto_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -354,9 354,7 @@ where
ty_to_bounds
.into_iter()
.flat_map(|(ty, mut bounds)| {
if let Some(data) = ty_to_fn.get(&ty) {
let (poly_trait, output) =
(data.0.as_ref().unwrap().clone(), data.1.as_ref().cloned().map(Box::new));
if let Some((Some(ref poly_trait), ref output)) = ty_to_fn.get(&ty) {
let mut new_path = poly_trait.trait_.clone();
let last_segment = new_path.segments.pop().expect("segments were empty");

Expand All @@ -374,8 372,9 @@ where
GenericArgs::Parenthesized { inputs, output } => (inputs, output),
};

let output = output.as_ref().cloned().map(Box::new);
if old_output.is_some() && old_output != output {
panic!("Output mismatch for {:?} {:?} {:?}", ty, old_output, data.1);
panic!("Output mismatch for {:?} {:?} {:?}", ty, old_output, output);
}

let new_params = GenericArgs::Parenthesized { inputs: old_input, output };
Expand All @@ -385,7 384,10 @@ where
.push(PathSegment { name: last_segment.name, args: new_params });

bounds.insert(GenericBound::TraitBound(
PolyTrait { trait_: new_path, generic_params: poly_trait.generic_params },
PolyTrait {
trait_: new_path,
generic_params: poly_trait.generic_params.clone(),
},
hir::TraitBoundModifier::None,
));
}
Expand Down
17 changes: 17 additions & 0 deletions src/test/rustdoc/fn-bound.rs
Original file line number Diff line number Diff line change
@@ -0,0 1,17 @@
use std::iter::Peekable;

pub struct Span<F: Fn(&i32)> {
inner: Peekable<ConditionalIterator<F>>,
}

struct ConditionalIterator<F> {
f: F,
}

impl<F: Fn(&i32)> Iterator for ConditionalIterator<F> {
type Item = ();

fn next(&mut self) -> Option<Self::Item> {
todo!()
}
}

0 comments on commit 7c45c50

Please sign in to comment.