Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit c4c76a4

Browse files
committed
Document flip polarity
1 parent 7829d9d commit c4c76a4

File tree

2 files changed

+7
-0
lines changed
  • compiler

2 files changed

+7
-0
lines changed

compiler/rustc_infer/src/traits/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ pub type PredicateObligation<'tcx> = Obligation<'tcx, ty::Predicate<'tcx>>;
5656
pub type TraitObligation<'tcx> = Obligation<'tcx, ty::PolyTraitPredicate<'tcx>>;
5757

5858
impl PredicateObligation<'tcx> {
59+
/// Flips the polarity of the inner predicate.
60+
///
61+
/// Given `T: Trait` predicate it returns `T: !Trait` and given `T: !Trait` returns `T: Trait`.
5962
pub fn flip_polarity(&self, tcx: TyCtxt<'tcx>) -> Option<PredicateObligation<'tcx>> {
6063
Some(PredicateObligation {
6164
cause: self.cause.clone(),

compiler/rustc_middle/src/ty/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ pub enum ImplPolarity {
190190
}
191191

192192
impl ImplPolarity {
193+
/// Flips polarity by turning `Positive` into `Negative` and `Negative` into `Positive`.
193194
pub fn flip(&self) -> Option<ImplPolarity> {
194195
match self {
195196
ImplPolarity::Positive => Some(ImplPolarity::Negative),
@@ -492,6 +493,9 @@ impl<'tcx> Predicate<'tcx> {
492493
self.inner.kind
493494
}
494495

496+
/// Flips the polarity of a Predicate.
497+
///
498+
/// Given `T: Trait` predicate it returns `T: !Trait` and given `T: !Trait` returns `T: Trait`.
495499
pub fn flip_polarity(&self, tcx: TyCtxt<'tcx>) -> Option<Predicate<'tcx>> {
496500
let kind = self
497501
.inner

0 commit comments

Comments
 (0)