Skip to content

Commit e4fedf4

Browse files
committed
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
1 parent 4c2be9c commit e4fedf4

File tree

2 files changed

+37
-15
lines changed

2 files changed

+37
-15
lines changed

src/librustdoc/clean/auto_trait.rs

+4
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,10 @@ impl<'a, 'tcx, 'rcx> AutoTraitFinder<'a, 'tcx, 'rcx> {
574574
let mut ty_to_fn: FxHashMap<Type, (Option<PolyTrait>, Option<Type>)> = Default::default();
575575

576576
for (orig_p, p) in clean_where_predicates {
577+
if p.is_none() {
578+
continue;
579+
}
580+
let p = p.unwrap();
577581
match p {
578582
WherePredicate::BoundPredicate { ty, mut bounds } => {
579583
// Writing a projection trait bound of the form

src/librustdoc/clean/mod.rs

+33-15
Original file line numberDiff line numberDiff line change
@@ -1271,7 +1271,10 @@ impl Clean<Option<Lifetime>> for ty::RegionKind {
12711271
ty::RePlaceholder(..) |
12721272
ty::ReEmpty |
12731273
ty::ReClosureBound(_) |
1274-
ty::ReErased => None
1274+
ty::ReErased => {
1275+
debug!("Cannot clean region {:?}", self);
1276+
None
1277+
}
12751278
}
12761279
}
12771280
}
@@ -1310,16 +1313,16 @@ impl Clean<WherePredicate> for hir::WherePredicate {
13101313
}
13111314
}
13121315

1313-
impl<'a> Clean<WherePredicate> for ty::Predicate<'a> {
1314-
fn clean(&self, cx: &DocContext) -> WherePredicate {
1316+
impl<'a> Clean<Option<WherePredicate>> for ty::Predicate<'a> {
1317+
fn clean(&self, cx: &DocContext) -> Option<WherePredicate> {
13151318
use rustc::ty::Predicate;
13161319

13171320
match *self {
1318-
Predicate::Trait(ref pred) => pred.clean(cx),
1319-
Predicate::Subtype(ref pred) => pred.clean(cx),
1321+
Predicate::Trait(ref pred) => Some(pred.clean(cx)),
1322+
Predicate::Subtype(ref pred) => Some(pred.clean(cx)),
13201323
Predicate::RegionOutlives(ref pred) => pred.clean(cx),
13211324
Predicate::TypeOutlives(ref pred) => pred.clean(cx),
1322-
Predicate::Projection(ref pred) => pred.clean(cx),
1325+
Predicate::Projection(ref pred) => Some(pred.clean(cx)),
13231326

13241327
Predicate::WellFormed(..) |
13251328
Predicate::ObjectSafe(..) |
@@ -1345,24 +1348,39 @@ impl<'tcx> Clean<WherePredicate> for ty::SubtypePredicate<'tcx> {
13451348
}
13461349
}
13471350

1348-
impl<'tcx> Clean<WherePredicate> for ty::OutlivesPredicate<ty::Region<'tcx>, ty::Region<'tcx>> {
1349-
fn clean(&self, cx: &DocContext) -> WherePredicate {
1351+
impl<'tcx> Clean<Option<WherePredicate>> for
1352+
ty::OutlivesPredicate<ty::Region<'tcx>,ty::Region<'tcx>> {
1353+
1354+
fn clean(&self, cx: &DocContext) -> Option<WherePredicate> {
13501355
let ty::OutlivesPredicate(ref a, ref b) = *self;
1351-
WherePredicate::RegionPredicate {
1356+
1357+
match (a, b) {
1358+
(ty::ReEmpty, ty::ReEmpty) => {
1359+
return None;
1360+
},
1361+
_ => {}
1362+
}
1363+
1364+
Some(WherePredicate::RegionPredicate {
13521365
lifetime: a.clean(cx).expect("failed to clean lifetime"),
13531366
bounds: vec![GenericBound::Outlives(b.clean(cx).expect("failed to clean bounds"))]
1354-
}
1367+
})
13551368
}
13561369
}
13571370

1358-
impl<'tcx> Clean<WherePredicate> for ty::OutlivesPredicate<Ty<'tcx>, ty::Region<'tcx>> {
1359-
fn clean(&self, cx: &DocContext) -> WherePredicate {
1371+
impl<'tcx> Clean<Option<WherePredicate>> for ty::OutlivesPredicate<Ty<'tcx>, ty::Region<'tcx>> {
1372+
fn clean(&self, cx: &DocContext) -> Option<WherePredicate> {
13601373
let ty::OutlivesPredicate(ref ty, ref lt) = *self;
13611374

1362-
WherePredicate::BoundPredicate {
1375+
match lt {
1376+
ty::ReEmpty => return None,
1377+
_ => {}
1378+
}
1379+
1380+
Some(WherePredicate::BoundPredicate {
13631381
ty: ty.clean(cx),
13641382
bounds: vec![GenericBound::Outlives(lt.clean(cx).expect("failed to clean lifetimes"))]
1365-
}
1383+
})
13661384
}
13671385
}
13681386

@@ -1579,7 +1597,7 @@ impl<'a, 'tcx> Clean<Generics> for (&'a ty::Generics,
15791597
}).collect::<Vec<GenericParamDef>>();
15801598

15811599
let mut where_predicates = preds.predicates.iter()
1582-
.map(|(p, _)| p.clean(cx))
1600+
.flat_map(|(p, _)| p.clean(cx))
15831601
.collect::<Vec<_>>();
15841602

15851603
// Type parameters and have a Sized bound by default unless removed with

0 commit comments

Comments
 (0)