Skip to content

Commit 574042c

Browse files
committed
rustdoc: Properly clean middle::ty negative bounds
1 parent f3b0947 commit 574042c

File tree

1 file changed

+26
-16
lines changed

1 file changed

+26
-16
lines changed

src/librustdoc/clean/mod.rs

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -271,14 +271,11 @@ fn clean_poly_trait_ref_with_constraints<'tcx>(
271271
cx: &mut DocContext<'tcx>,
272272
poly_trait_ref: ty::PolyTraitRef<'tcx>,
273273
constraints: ThinVec<AssocItemConstraint>,
274-
) -> GenericBound {
275-
GenericBound::TraitBound(
276-
PolyTrait {
277-
trait_: clean_trait_ref_with_constraints(cx, poly_trait_ref, constraints),
278-
generic_params: clean_bound_vars(poly_trait_ref.bound_vars(), cx),
279-
},
280-
hir::TraitBoundModifiers::NONE,
281-
)
274+
) -> PolyTrait {
275+
PolyTrait {
276+
trait_: clean_trait_ref_with_constraints(cx, poly_trait_ref, constraints),
277+
generic_params: clean_bound_vars(poly_trait_ref.bound_vars(), cx),
278+
}
282279
}
283280

284281
fn clean_lifetime(lifetime: &hir::Lifetime, cx: &DocContext<'_>) -> Lifetime {
@@ -403,16 +400,28 @@ fn clean_poly_trait_predicate<'tcx>(
403400
) -> Option<WherePredicate> {
404401
// `T: [const] Destruct` is hidden because `T: Destruct` is a no-op.
405402
// FIXME(const_trait_impl) check constness
406-
if Some(pred.skip_binder().def_id()) == cx.tcx.lang_items().destruct_trait() {
403+
if Some(pred.def_id()) == cx.tcx.lang_items().destruct_trait() {
407404
return None;
408405
}
409406

410-
let poly_trait_ref = pred.map_bound(|pred| pred.trait_ref);
411-
Some(WherePredicate::BoundPredicate {
412-
ty: clean_middle_ty(poly_trait_ref.self_ty(), cx, None, None),
413-
bounds: vec![clean_poly_trait_ref_with_constraints(cx, poly_trait_ref, ThinVec::new())],
414-
bound_params: Vec::new(),
415-
})
407+
let trait_ref = pred.map_bound(|pred| pred.trait_ref);
408+
409+
let ty = clean_middle_ty(trait_ref.self_ty(), cx, None, None);
410+
411+
let bound = GenericBound::TraitBound(
412+
clean_poly_trait_ref_with_constraints(cx, trait_ref, ThinVec::new()),
413+
hir::TraitBoundModifiers {
414+
polarity: match pred.polarity() {
415+
ty::PredicatePolarity::Positive => hir::BoundPolarity::Positive,
416+
ty::PredicatePolarity::Negative => {
417+
rustc_ast::BoundPolarity::Negative(rustc_span::DUMMY_SP)
418+
}
419+
},
420+
constness: hir::BoundConstness::Never,
421+
},
422+
);
423+
424+
Some(WherePredicate::BoundPredicate { ty, bounds: vec![bound], bound_params: Vec::new() })
416425
}
417426

418427
fn clean_region_outlives_predicate<'tcx>(
@@ -2316,7 +2325,8 @@ fn clean_middle_opaque_bounds<'tcx>(
23162325
})
23172326
.collect();
23182327

2319-
Some(clean_poly_trait_ref_with_constraints(cx, trait_ref, bindings))
2328+
let trait_ref = clean_poly_trait_ref_with_constraints(cx, trait_ref, bindings);
2329+
Some(GenericBound::TraitBound(trait_ref, hir::TraitBoundModifiers::NONE))
23202330
})
23212331
.collect::<Vec<_>>();
23222332

0 commit comments

Comments
 (0)