From e4fedf4be4c0cf735787bc81ff5ea0d7086fe6cd Mon Sep 17 00:00:00 2001 From: Aaron Hill Date: Tue, 22 Jan 2019 19:54:30 -0500 Subject: [PATCH] Don't try to clean predicates involving ReErased There's nothing to render when we have a bound involving ReErased (either a type or region outliving it), so we don't attempt to generate a clean WherePredicate Fixes #57806 --- src/librustdoc/clean/auto_trait.rs | 4 +++ src/librustdoc/clean/mod.rs | 48 ++++++++++++++++++++---------- 2 files changed, 37 insertions(+), 15 deletions(-) diff --git a/src/librustdoc/clean/auto_trait.rs b/src/librustdoc/clean/auto_trait.rs index 27ca205720d6a..b99181c0d4f9e 100644 --- a/src/librustdoc/clean/auto_trait.rs +++ b/src/librustdoc/clean/auto_trait.rs @@ -574,6 +574,10 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> { let mut ty_to_fn: FxHashMap, Option)> = Default::default(); for (orig_p, p) in clean_where_predicates { + if p.is_none() { + continue; + } + let p = p.unwrap(); match p { WherePredicate::BoundPredicate { ty, mut bounds } => { // Writing a projection trait bound of the form diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 6eea95b61c990..a7ce0520b6d3d 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -1271,7 +1271,10 @@ impl Clean> for ty::RegionKind { ty::RePlaceholder(..) | ty::ReEmpty | ty::ReClosureBound(_) | - ty::ReErased => None + ty::ReErased => { + debug!("Cannot clean region {:?}", self); + None + } } } } @@ -1310,16 +1313,16 @@ impl Clean for hir::WherePredicate { } } -impl<'a> Clean for ty::Predicate<'a> { - fn clean(&self, cx: &DocContext) -> WherePredicate { +impl<'a> Clean> for ty::Predicate<'a> { + fn clean(&self, cx: &DocContext) -> Option { use rustc::ty::Predicate; match *self { - Predicate::Trait(ref pred) => pred.clean(cx), - Predicate::Subtype(ref pred) => pred.clean(cx), + Predicate::Trait(ref pred) => Some(pred.clean(cx)), + Predicate::Subtype(ref pred) => Some(pred.clean(cx)), Predicate::RegionOutlives(ref pred) => pred.clean(cx), Predicate::TypeOutlives(ref pred) => pred.clean(cx), - Predicate::Projection(ref pred) => pred.clean(cx), + Predicate::Projection(ref pred) => Some(pred.clean(cx)), Predicate::WellFormed(..) | Predicate::ObjectSafe(..) | @@ -1345,24 +1348,39 @@ impl<'tcx> Clean for ty::SubtypePredicate<'tcx> { } } -impl<'tcx> Clean for ty::OutlivesPredicate, ty::Region<'tcx>> { - fn clean(&self, cx: &DocContext) -> WherePredicate { +impl<'tcx> Clean> for + ty::OutlivesPredicate,ty::Region<'tcx>> { + + fn clean(&self, cx: &DocContext) -> Option { let ty::OutlivesPredicate(ref a, ref b) = *self; - WherePredicate::RegionPredicate { + + match (a, b) { + (ty::ReEmpty, ty::ReEmpty) => { + return None; + }, + _ => {} + } + + Some(WherePredicate::RegionPredicate { lifetime: a.clean(cx).expect("failed to clean lifetime"), bounds: vec![GenericBound::Outlives(b.clean(cx).expect("failed to clean bounds"))] - } + }) } } -impl<'tcx> Clean for ty::OutlivesPredicate, ty::Region<'tcx>> { - fn clean(&self, cx: &DocContext) -> WherePredicate { +impl<'tcx> Clean> for ty::OutlivesPredicate, ty::Region<'tcx>> { + fn clean(&self, cx: &DocContext) -> Option { let ty::OutlivesPredicate(ref ty, ref lt) = *self; - WherePredicate::BoundPredicate { + match lt { + ty::ReEmpty => return None, + _ => {} + } + + Some(WherePredicate::BoundPredicate { ty: ty.clean(cx), bounds: vec![GenericBound::Outlives(lt.clean(cx).expect("failed to clean lifetimes"))] - } + }) } } @@ -1579,7 +1597,7 @@ impl<'a, 'tcx> Clean for (&'a ty::Generics, }).collect::>(); let mut where_predicates = preds.predicates.iter() - .map(|(p, _)| p.clean(cx)) + .flat_map(|(p, _)| p.clean(cx)) .collect::>(); // Type parameters and have a Sized bound by default unless removed with