From 4443fd5d76c6c28bb5954463ee35daf4ee508d81 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Tue, 26 Jul 2022 15:10:39 -0700 Subject: [PATCH 1/4] rustdoc: remove Clean trait impl for ProjectionTy --- src/librustdoc/clean/mod.rs | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 07237438a0d32..a9141b5f45141 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -421,7 +421,10 @@ impl<'tcx> Clean<'tcx, Term> for hir::Term<'tcx> { impl<'tcx> Clean<'tcx, WherePredicate> for ty::ProjectionPredicate<'tcx> { fn clean(&self, cx: &mut DocContext<'tcx>) -> WherePredicate { let ty::ProjectionPredicate { projection_ty, term } = self; - WherePredicate::EqPredicate { lhs: projection_ty.clean(cx), rhs: term.clean(cx) } + WherePredicate::EqPredicate { + lhs: clean_projection(*projection_ty, cx, None), + rhs: term.clean(cx), + } } } @@ -447,12 +450,6 @@ fn clean_projection<'tcx>( } } -impl<'tcx> Clean<'tcx, Type> for ty::ProjectionTy<'tcx> { - fn clean(&self, cx: &mut DocContext<'tcx>) -> Type { - clean_projection(*self, cx, None) - } -} - fn compute_should_show_cast(self_def_id: Option, trait_: &Path, self_type: &Type) -> bool { !trait_.segments.is_empty() && self_def_id @@ -734,8 +731,12 @@ fn clean_ty_generics<'tcx>( .filter(|b| !b.is_sized_bound(cx)), ); - let proj = projection - .map(|p| (p.skip_binder().projection_ty.clean(cx), p.skip_binder().term)); + let proj = projection.map(|p| { + ( + clean_projection(p.skip_binder().projection_ty, cx, None), + p.skip_binder().term, + ) + }); if let Some(((_, trait_did, name), rhs)) = proj .as_ref() .and_then(|(lhs, rhs): &(Type, _)| Some((lhs.projection()?, rhs))) From 791beb7a5c7b36a61d9820943c9566425ec91377 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Tue, 26 Jul 2022 15:16:51 -0700 Subject: [PATCH 2/4] rustdoc: remove Clean trait impl for ProjectionPredicate --- src/librustdoc/clean/mod.rs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index a9141b5f45141..63908e167e3e0 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -330,7 +330,7 @@ impl<'tcx> Clean<'tcx, Option> for ty::Predicate<'tcx> { ty::PredicateKind::Trait(pred) => bound_predicate.rebind(pred).clean(cx), ty::PredicateKind::RegionOutlives(pred) => pred.clean(cx), ty::PredicateKind::TypeOutlives(pred) => pred.clean(cx), - ty::PredicateKind::Projection(pred) => Some(pred.clean(cx)), + ty::PredicateKind::Projection(pred) => Some(clean_projection_predicate(pred, cx)), ty::PredicateKind::ConstEvaluatable(..) => None, ty::PredicateKind::WellFormed(..) => None, @@ -418,13 +418,14 @@ impl<'tcx> Clean<'tcx, Term> for hir::Term<'tcx> { } } -impl<'tcx> Clean<'tcx, WherePredicate> for ty::ProjectionPredicate<'tcx> { - fn clean(&self, cx: &mut DocContext<'tcx>) -> WherePredicate { - let ty::ProjectionPredicate { projection_ty, term } = self; - WherePredicate::EqPredicate { - lhs: clean_projection(*projection_ty, cx, None), - rhs: term.clean(cx), - } +fn clean_projection_predicate<'tcx>( + pred: ty::ProjectionPredicate<'tcx>, + cx: &mut DocContext<'tcx>, +) -> WherePredicate { + let ty::ProjectionPredicate { projection_ty, term } = pred; + WherePredicate::EqPredicate { + lhs: clean_projection(projection_ty, cx, None), + rhs: term.clean(cx), } } From e94ef5cc769db15492e2d004e88a2114b307e33a Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Tue, 26 Jul 2022 15:28:20 -0700 Subject: [PATCH 3/4] rustdoc: remove Clean trait impls for ty::OutlivesPredicate --- src/librustdoc/clean/mod.rs | 56 ++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 29 deletions(-) diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 63908e167e3e0..2ee59663ec344 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -328,8 +328,8 @@ impl<'tcx> Clean<'tcx, Option> for ty::Predicate<'tcx> { let bound_predicate = self.kind(); match bound_predicate.skip_binder() { ty::PredicateKind::Trait(pred) => bound_predicate.rebind(pred).clean(cx), - ty::PredicateKind::RegionOutlives(pred) => pred.clean(cx), - ty::PredicateKind::TypeOutlives(pred) => pred.clean(cx), + ty::PredicateKind::RegionOutlives(pred) => clean_region_outlives_predicate(pred, cx), + ty::PredicateKind::TypeOutlives(pred) => clean_type_outlives_predicate(pred, cx), ty::PredicateKind::Projection(pred) => Some(clean_projection_predicate(pred, cx)), ty::PredicateKind::ConstEvaluatable(..) => None, ty::PredicateKind::WellFormed(..) => None, @@ -362,39 +362,37 @@ impl<'tcx> Clean<'tcx, Option> for ty::PolyTraitPredicate<'tcx> } } -impl<'tcx> Clean<'tcx, Option> - for ty::OutlivesPredicate, ty::Region<'tcx>> -{ - fn clean(&self, cx: &mut DocContext<'tcx>) -> Option { - let ty::OutlivesPredicate(a, b) = self; - - if a.is_empty() && b.is_empty() { - return None; - } +fn clean_region_outlives_predicate<'tcx>( + pred: ty::OutlivesPredicate, ty::Region<'tcx>>, + cx: &mut DocContext<'tcx>, +) -> Option { + let ty::OutlivesPredicate(a, b) = pred; - Some(WherePredicate::RegionPredicate { - lifetime: a.clean(cx).expect("failed to clean lifetime"), - bounds: vec![GenericBound::Outlives(b.clean(cx).expect("failed to clean bounds"))], - }) + if a.is_empty() && b.is_empty() { + return None; } -} -impl<'tcx> Clean<'tcx, Option> - for ty::OutlivesPredicate, ty::Region<'tcx>> -{ - fn clean(&self, cx: &mut DocContext<'tcx>) -> Option { - let ty::OutlivesPredicate(ty, lt) = self; + Some(WherePredicate::RegionPredicate { + lifetime: a.clean(cx).expect("failed to clean lifetime"), + bounds: vec![GenericBound::Outlives(b.clean(cx).expect("failed to clean bounds"))], + }) +} - if lt.is_empty() { - return None; - } +fn clean_type_outlives_predicate<'tcx>( + pred: ty::OutlivesPredicate, ty::Region<'tcx>>, + cx: &mut DocContext<'tcx>, +) -> Option { + let ty::OutlivesPredicate(ty, lt) = pred; - Some(WherePredicate::BoundPredicate { - ty: clean_middle_ty(*ty, cx, None), - bounds: vec![GenericBound::Outlives(lt.clean(cx).expect("failed to clean lifetimes"))], - bound_params: Vec::new(), - }) + if lt.is_empty() { + return None; } + + Some(WherePredicate::BoundPredicate { + ty: clean_middle_ty(ty, cx, None), + bounds: vec![GenericBound::Outlives(lt.clean(cx).expect("failed to clean lifetimes"))], + bound_params: Vec::new(), + }) } impl<'tcx> Clean<'tcx, Term> for ty::Term<'tcx> { From 9dcf1d9c1a5184f861c299f4e793169445460a24 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Tue, 26 Jul 2022 15:32:32 -0700 Subject: [PATCH 4/4] rustdoc: remove Clean trait impl for ty::PolyTraitPredicate --- src/librustdoc/clean/mod.rs | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 2ee59663ec344..2f3ca41723d85 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -327,7 +327,9 @@ impl<'tcx> Clean<'tcx, Option> for ty::Predicate<'tcx> { fn clean(&self, cx: &mut DocContext<'tcx>) -> Option { let bound_predicate = self.kind(); match bound_predicate.skip_binder() { - ty::PredicateKind::Trait(pred) => bound_predicate.rebind(pred).clean(cx), + ty::PredicateKind::Trait(pred) => { + clean_poly_trait_predicate(bound_predicate.rebind(pred), cx) + } ty::PredicateKind::RegionOutlives(pred) => clean_region_outlives_predicate(pred, cx), ty::PredicateKind::TypeOutlives(pred) => clean_type_outlives_predicate(pred, cx), ty::PredicateKind::Projection(pred) => Some(clean_projection_predicate(pred, cx)), @@ -344,22 +346,23 @@ impl<'tcx> Clean<'tcx, Option> for ty::Predicate<'tcx> { } } -impl<'tcx> Clean<'tcx, Option> for ty::PolyTraitPredicate<'tcx> { - fn clean(&self, cx: &mut DocContext<'tcx>) -> Option { - // `T: ~const Destruct` is hidden because `T: Destruct` is a no-op. - if self.skip_binder().constness == ty::BoundConstness::ConstIfConst - && Some(self.skip_binder().def_id()) == cx.tcx.lang_items().destruct_trait() - { - return None; - } - - let poly_trait_ref = self.map_bound(|pred| pred.trait_ref); - Some(WherePredicate::BoundPredicate { - ty: clean_middle_ty(poly_trait_ref.skip_binder().self_ty(), cx, None), - bounds: vec![poly_trait_ref.clean(cx)], - bound_params: Vec::new(), - }) +fn clean_poly_trait_predicate<'tcx>( + pred: ty::PolyTraitPredicate<'tcx>, + cx: &mut DocContext<'tcx>, +) -> Option { + // `T: ~const Destruct` is hidden because `T: Destruct` is a no-op. + if pred.skip_binder().constness == ty::BoundConstness::ConstIfConst + && Some(pred.skip_binder().def_id()) == cx.tcx.lang_items().destruct_trait() + { + return None; } + + let poly_trait_ref = pred.map_bound(|pred| pred.trait_ref); + Some(WherePredicate::BoundPredicate { + ty: clean_middle_ty(poly_trait_ref.skip_binder().self_ty(), cx, None), + bounds: vec![poly_trait_ref.clean(cx)], + bound_params: Vec::new(), + }) } fn clean_region_outlives_predicate<'tcx>(