@@ -456,6 +456,11 @@ impl ty::EarlyBoundRegion {
456
456
}
457
457
}
458
458
459
+ /// A statement that can be proven by a trait solver. This includes things that may
460
+ /// show up in where clauses, such as trait predicates and projection predicates,
461
+ /// and also things that are emitted as part of type checking such as `ObjectSafe`
462
+ /// predicate which is emitted when a type is coerced to a trait object.
463
+ ///
459
464
/// Use this rather than `PredicateKind`, whenever possible.
460
465
#[ derive( Clone , Copy , PartialEq , Eq , Hash , HashStable ) ]
461
466
#[ rustc_pass_by_value]
@@ -561,7 +566,9 @@ impl rustc_errors::IntoDiagnosticArg for Predicate<'_> {
561
566
}
562
567
}
563
568
564
- /// TODO: doc
569
+ /// A subset of predicates which can be assumed by the trait solver. They show up in
570
+ /// an item's where clauses, hence the name `Clause`, and may either be user-written
571
+ /// (such as traits) or may be inserted during lowering.
565
572
#[ derive( Clone , Copy , PartialEq , Eq , Hash , HashStable ) ]
566
573
#[ rustc_pass_by_value]
567
574
pub struct Clause < ' tcx > ( Interned < ' tcx , WithCachedTypeInfo < ty:: Binder < ' tcx , PredicateKind < ' tcx > > > > ) ;
@@ -1409,13 +1416,16 @@ impl<'tcx> Predicate<'tcx> {
1409
1416
}
1410
1417
}
1411
1418
1419
+ /// Matches a `PredicateKind::Clause` and turns it into a `Clause`, otherwise returns `None`.
1412
1420
pub fn as_clause ( self ) -> Option < Clause < ' tcx > > {
1413
1421
match self . kind ( ) . skip_binder ( ) {
1414
1422
PredicateKind :: Clause ( ..) => Some ( self . expect_clause ( ) ) ,
1415
1423
_ => None ,
1416
1424
}
1417
1425
}
1418
1426
1427
+ /// Turns a predicate into a clause without checking that it is a `PredicateKind::Clause`
1428
+ /// first. This will ICE when methods are called on `Clause`.
1419
1429
pub fn expect_clause ( self ) -> Clause < ' tcx > {
1420
1430
match self . kind ( ) . skip_binder ( ) {
1421
1431
PredicateKind :: Clause ( ..) => Clause ( self . 0 ) ,
0 commit comments