diff options
| author | Santiago Pastorino <spastorino@gmail.com> | 2021-10-22 09:34:36 -0300 |
|---|---|---|
| committer | Santiago Pastorino <spastorino@gmail.com> | 2021-10-22 09:34:36 -0300 |
| commit | c4c76a4fbd046066eb5490d7e5aec4c263e12fde (patch) | |
| tree | f29c4917066fffc4ec5bd6988e45f4050cefcd80 | |
| parent | 7829d9dde3798f16b3db5841593ba1242930a587 (diff) | |
| download | rust-c4c76a4fbd046066eb5490d7e5aec4c263e12fde.tar.gz rust-c4c76a4fbd046066eb5490d7e5aec4c263e12fde.zip | |
Document flip polarity
| -rw-r--r-- | compiler/rustc_infer/src/traits/mod.rs | 3 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/ty/mod.rs | 4 |
2 files changed, 7 insertions, 0 deletions
diff --git a/compiler/rustc_infer/src/traits/mod.rs b/compiler/rustc_infer/src/traits/mod.rs index 033d634cdb7..e8622b3c819 100644 --- a/compiler/rustc_infer/src/traits/mod.rs +++ b/compiler/rustc_infer/src/traits/mod.rs @@ -56,6 +56,9 @@ pub type PredicateObligation<'tcx> = Obligation<'tcx, ty::Predicate<'tcx>>; pub type TraitObligation<'tcx> = Obligation<'tcx, ty::PolyTraitPredicate<'tcx>>; impl PredicateObligation<'tcx> { + /// Flips the polarity of the inner predicate. + /// + /// Given `T: Trait` predicate it returns `T: !Trait` and given `T: !Trait` returns `T: Trait`. pub fn flip_polarity(&self, tcx: TyCtxt<'tcx>) -> Option<PredicateObligation<'tcx>> { Some(PredicateObligation { cause: self.cause.clone(), diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index 98354d7844b..dfdb5eba7f2 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -190,6 +190,7 @@ pub enum ImplPolarity { } impl ImplPolarity { + /// Flips polarity by turning `Positive` into `Negative` and `Negative` into `Positive`. pub fn flip(&self) -> Option<ImplPolarity> { match self { ImplPolarity::Positive => Some(ImplPolarity::Negative), @@ -492,6 +493,9 @@ impl<'tcx> Predicate<'tcx> { self.inner.kind } + /// Flips the polarity of a Predicate. + /// + /// Given `T: Trait` predicate it returns `T: !Trait` and given `T: !Trait` returns `T: Trait`. pub fn flip_polarity(&self, tcx: TyCtxt<'tcx>) -> Option<Predicate<'tcx>> { let kind = self .inner |
