From d677a2d73b87926c5fa359b47830de39ab0e9626 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Thu, 21 Mar 2024 15:53:21 -0400 Subject: [PATCH] Further simplifications --- compiler/rustc_middle/src/ty/error.rs | 2 +- compiler/rustc_middle/src/ty/mod.rs | 23 +++-------------------- compiler/rustc_middle/src/ty/relate.rs | 16 +--------------- 3 files changed, 5 insertions(+), 36 deletions(-) diff --git a/compiler/rustc_middle/src/ty/error.rs b/compiler/rustc_middle/src/ty/error.rs index e15f03788464e..a2d674b9c4402 100644 --- a/compiler/rustc_middle/src/ty/error.rs +++ b/compiler/rustc_middle/src/ty/error.rs @@ -32,7 +32,7 @@ impl ExpectedFound { pub enum TypeError<'tcx> { Mismatch, ConstnessMismatch(ExpectedFound), - PolarityMismatch(ExpectedFound), + PolarityMismatch(ExpectedFound), UnsafetyMismatch(ExpectedFound), AbiMismatch(ExpectedFound), Mutability, diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index b2fa944b34fe3..6ce53ccc8cd7a 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -280,17 +280,6 @@ pub enum ImplPolarity { Reservation, } -impl ImplPolarity { - /// Flips polarity by turning `Positive` into `Negative` and `Negative` into `Positive`. - pub fn flip(&self) -> Option { - match self { - ImplPolarity::Positive => Some(ImplPolarity::Negative), - ImplPolarity::Negative => Some(ImplPolarity::Positive), - ImplPolarity::Reservation => None, - } - } -} - impl fmt::Display for ImplPolarity { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { @@ -301,15 +290,9 @@ impl fmt::Display for ImplPolarity { } } -impl From for ImplPolarity { - fn from(value: PredicatePolarity) -> Self { - match value { - PredicatePolarity::Positive => ImplPolarity::Positive, - PredicatePolarity::Negative => ImplPolarity::Negative, - } - } -} - +/// Polarity for a trait predicate. May either be negative or positive. +/// Distinguished from [`ImplPolarity`] since we never compute goals with +/// "reservation" level. #[derive(Copy, Clone, PartialEq, Eq, Hash, TyEncodable, TyDecodable, HashStable, Debug)] #[derive(TypeFoldable, TypeVisitable)] pub enum PredicatePolarity { diff --git a/compiler/rustc_middle/src/ty/relate.rs b/compiler/rustc_middle/src/ty/relate.rs index cb43ae93c8dcd..f523fd7b75a1d 100644 --- a/compiler/rustc_middle/src/ty/relate.rs +++ b/compiler/rustc_middle/src/ty/relate.rs @@ -769,27 +769,13 @@ impl<'tcx> Relate<'tcx> for GenericArg<'tcx> { } } -impl<'tcx> Relate<'tcx> for ty::ImplPolarity { - fn relate>( - _relation: &mut R, - a: ty::ImplPolarity, - b: ty::ImplPolarity, - ) -> RelateResult<'tcx, ty::ImplPolarity> { - if a != b { Err(TypeError::PolarityMismatch(expected_found(a, b))) } else { Ok(a) } - } -} - impl<'tcx> Relate<'tcx> for ty::PredicatePolarity { fn relate>( _relation: &mut R, a: ty::PredicatePolarity, b: ty::PredicatePolarity, ) -> RelateResult<'tcx, ty::PredicatePolarity> { - if a != b { - Err(TypeError::PolarityMismatch(expected_found(a.into(), b.into()))) - } else { - Ok(a) - } + if a != b { Err(TypeError::PolarityMismatch(expected_found(a, b))) } else { Ok(a) } } }