Skip to content

Commit ca38733

Browse files
cjgillotMark-Simulacrum
authored andcommitted
Synthetize a trait ref when none is available.
1 parent 9d1fd97 commit ca38733

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

src/librustdoc/clean/auto_trait.rs

+12-6
Original file line numberDiff line numberDiff line change
@@ -345,13 +345,13 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
345345
fn make_final_bounds(
346346
&self,
347347
ty_to_bounds: FxHashMap<Type, FxHashSet<GenericBound>>,
348-
ty_to_fn: FxHashMap<Type, (Option<PolyTrait>, Option<Type>)>,
348+
ty_to_fn: FxHashMap<Type, (PolyTrait, Option<Type>)>,
349349
lifetime_to_bounds: FxHashMap<Lifetime, FxHashSet<GenericBound>>,
350350
) -> Vec<WherePredicate> {
351351
ty_to_bounds
352352
.into_iter()
353353
.flat_map(|(ty, mut bounds)| {
354-
if let Some((Some(ref poly_trait), ref output)) = ty_to_fn.get(&ty) {
354+
if let Some((ref poly_trait, ref output)) = ty_to_fn.get(&ty) {
355355
let mut new_path = poly_trait.trait_.clone();
356356
let last_segment = new_path.segments.pop().expect("segments were empty");
357357

@@ -470,7 +470,7 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
470470
let mut lifetime_to_bounds: FxHashMap<_, FxHashSet<_>> = Default::default();
471471
let mut ty_to_traits: FxHashMap<Type, FxHashSet<Path>> = Default::default();
472472

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

475475
for p in clean_where_predicates {
476476
let (orig_p, p) = (p, p.clean(self.cx));
@@ -534,8 +534,8 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
534534
if is_fn {
535535
ty_to_fn
536536
.entry(ty.clone())
537-
.and_modify(|e| *e = (Some(poly_trait.clone()), e.1.clone()))
538-
.or_insert(((Some(poly_trait.clone())), None));
537+
.and_modify(|e| *e = (poly_trait.clone(), e.1.clone()))
538+
.or_insert(((poly_trait.clone()), None));
539539

540540
ty_to_bounds.entry(ty.clone()).or_default();
541541
} else {
@@ -558,7 +558,13 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
558558
.and_modify(|e| {
559559
*e = (e.0.clone(), Some(rhs.ty().unwrap().clone()))
560560
})
561-
.or_insert((None, Some(rhs.ty().unwrap().clone())));
561+
.or_insert((
562+
PolyTrait {
563+
trait_: trait_.clone(),
564+
generic_params: Vec::new(),
565+
},
566+
Some(rhs.ty().unwrap().clone()),
567+
));
562568
continue;
563569
}
564570

src/test/rustdoc/fn-bound.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ pub struct Span<F: Fn(&i32)> {
44
inner: Peekable<ConditionalIterator<F>>,
55
}
66

7-
struct ConditionalIterator<F> {
7+
pub struct ConditionalIterator<F> {
88
f: F,
99
}
1010

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

0 commit comments

Comments
 (0)