diff options
| author | Michael Goulet <michael@errs.io> | 2024-03-21 15:53:21 -0400 |
|---|---|---|
| committer | Michael Goulet <michael@errs.io> | 2024-03-22 11:16:57 -0400 |
| commit | d677a2d73b87926c5fa359b47830de39ab0e9626 (patch) | |
| tree | b1e3118f6e44d9e28bb52dd41240eb3d125ec35b | |
| parent | 560c6cc6026d653270c57a3cc00e2a4406e3d5fa (diff) | |
| download | rust-d677a2d73b87926c5fa359b47830de39ab0e9626.tar.gz rust-d677a2d73b87926c5fa359b47830de39ab0e9626.zip | |
Further simplifications
| -rw-r--r-- | compiler/rustc_middle/src/ty/error.rs | 2 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/ty/mod.rs | 23 | ||||
| -rw-r--r-- | 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 e15f0378846..a2d674b9c44 100644 --- a/compiler/rustc_middle/src/ty/error.rs +++ b/compiler/rustc_middle/src/ty/error.rs @@ -32,7 +32,7 @@ impl<T> ExpectedFound<T> { pub enum TypeError<'tcx> { Mismatch, ConstnessMismatch(ExpectedFound<ty::BoundConstness>), - PolarityMismatch(ExpectedFound<ty::ImplPolarity>), + PolarityMismatch(ExpectedFound<ty::PredicatePolarity>), UnsafetyMismatch(ExpectedFound<hir::Unsafety>), AbiMismatch(ExpectedFound<abi::Abi>), Mutability, diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index b2fa944b34f..6ce53ccc8cd 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<ImplPolarity> { - 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<PredicatePolarity> 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 cb43ae93c8d..f523fd7b75a 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<R: TypeRelation<'tcx>>( - _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<R: TypeRelation<'tcx>>( _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) } } } |
