1
Fork 0

Document flip polarity

This commit is contained in:
Santiago Pastorino 2021-10-22 09:34:36 -03:00
parent 7829d9dde3
commit c4c76a4fbd
No known key found for this signature in database
GPG key ID: 8131A24E0C79EFAF
2 changed files with 7 additions and 0 deletions

View file

@ -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