Further simplifications

This commit is contained in:
Michael Goulet
2024-03-21 15:53:21 -04:00
parent 560c6cc602
commit d677a2d73b
3 changed files with 5 additions and 36 deletions

View File

@@ -32,7 +32,7 @@ impl<T> ExpectedFound<T> {
pub enum TypeError<'tcx> { pub enum TypeError<'tcx> {
Mismatch, Mismatch,
ConstnessMismatch(ExpectedFound<ty::BoundConstness>), ConstnessMismatch(ExpectedFound<ty::BoundConstness>),
PolarityMismatch(ExpectedFound<ty::ImplPolarity>), PolarityMismatch(ExpectedFound<ty::PredicatePolarity>),
UnsafetyMismatch(ExpectedFound<hir::Unsafety>), UnsafetyMismatch(ExpectedFound<hir::Unsafety>),
AbiMismatch(ExpectedFound<abi::Abi>), AbiMismatch(ExpectedFound<abi::Abi>),
Mutability, Mutability,

View File

@@ -280,17 +280,6 @@ pub enum ImplPolarity {
Reservation, 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 { impl fmt::Display for ImplPolarity {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self { match self {
@@ -301,15 +290,9 @@ impl fmt::Display for ImplPolarity {
} }
} }
impl From<PredicatePolarity> for ImplPolarity { /// Polarity for a trait predicate. May either be negative or positive.
fn from(value: PredicatePolarity) -> Self { /// Distinguished from [`ImplPolarity`] since we never compute goals with
match value { /// "reservation" level.
PredicatePolarity::Positive => ImplPolarity::Positive,
PredicatePolarity::Negative => ImplPolarity::Negative,
}
}
}
#[derive(Copy, Clone, PartialEq, Eq, Hash, TyEncodable, TyDecodable, HashStable, Debug)] #[derive(Copy, Clone, PartialEq, Eq, Hash, TyEncodable, TyDecodable, HashStable, Debug)]
#[derive(TypeFoldable, TypeVisitable)] #[derive(TypeFoldable, TypeVisitable)]
pub enum PredicatePolarity { pub enum PredicatePolarity {

View File

@@ -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 { impl<'tcx> Relate<'tcx> for ty::PredicatePolarity {
fn relate<R: TypeRelation<'tcx>>( fn relate<R: TypeRelation<'tcx>>(
_relation: &mut R, _relation: &mut R,
a: ty::PredicatePolarity, a: ty::PredicatePolarity,
b: ty::PredicatePolarity, b: ty::PredicatePolarity,
) -> RelateResult<'tcx, ty::PredicatePolarity> { ) -> RelateResult<'tcx, ty::PredicatePolarity> {
if a != b { if a != b { Err(TypeError::PolarityMismatch(expected_found(a, b))) } else { Ok(a) }
Err(TypeError::PolarityMismatch(expected_found(a.into(), b.into())))
} else {
Ok(a)
}
} }
} }