Skip to content

Commit

Permalink
Synthetize a trait ref when none is available.
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 9d1fd97 commit ca38733
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
18 changes: 12 additions & 6 deletions src/librustdoc/clean/auto_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,13 +345,13 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
fn make_final_bounds(
&self,
ty_to_bounds: FxHashMap<Type, FxHashSet<GenericBound>>,
ty_to_fn: FxHashMap<Type, (Option<PolyTrait>, Option<Type>)>,
ty_to_fn: FxHashMap<Type, (PolyTrait, Option<Type>)>,
lifetime_to_bounds: FxHashMap<Lifetime, FxHashSet<GenericBound>>,
) -> Vec<WherePredicate> {
ty_to_bounds
.into_iter()
.flat_map(|(ty, mut bounds)| {
if let Some((Some(ref poly_trait), ref output)) = ty_to_fn.get(&ty) {
if let 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 Down Expand Up @@ -470,7 +470,7 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
let mut lifetime_to_bounds: FxHashMap<_, FxHashSet<_>> = Default::default();
let mut ty_to_traits: FxHashMap<Type, FxHashSet<Path>> = Default::default();

let mut ty_to_fn: FxHashMap<Type, (Option<PolyTrait>, Option<Type>)> = Default::default();
let mut ty_to_fn: FxHashMap<Type, (PolyTrait, Option<Type>)> = Default::default();

for p in clean_where_predicates {
let (orig_p, p) = (p, p.clean(self.cx));
Expand Down Expand Up @@ -534,8 +534,8 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
if is_fn {
ty_to_fn
.entry(ty.clone())
.and_modify(|e| *e = (Some(poly_trait.clone()), e.1.clone()))
.or_insert(((Some(poly_trait.clone())), None));
.and_modify(|e| *e = (poly_trait.clone(), e.1.clone()))
.or_insert(((poly_trait.clone()), None));

ty_to_bounds.entry(ty.clone()).or_default();
} else {
Expand All @@ -558,7 +558,13 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
.and_modify(|e| {
*e = (e.0.clone(), Some(rhs.ty().unwrap().clone()))
})
.or_insert((None, Some(rhs.ty().unwrap().clone())));
.or_insert((
PolyTrait {
trait_: trait_.clone(),
generic_params: Vec::new(),
},
Some(rhs.ty().unwrap().clone()),
));
continue;
}

Expand Down
4 changes: 3 additions & 1 deletion src/test/rustdoc/fn-bound.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ pub struct Span<F: Fn(&i32)> {
inner: Peekable<ConditionalIterator<F>>,
}

struct ConditionalIterator<F> {
pub struct ConditionalIterator<F> {
f: F,
}


// @has 'fn_bound/struct.ConditionalIterator.html' '//h3[@class="code-header in-band"]' 'impl<F: Fn(&i32)> Iterator for ConditionalIterator<F>'
impl<F: Fn(&i32)> Iterator for ConditionalIterator<F> {
type Item = ();

Expand Down

0 comments on commit ca38733

Please sign in to comment.