Skip to content

Commit

Permalink
Further simplifications
Browse files Browse the repository at this point in the history
  • Loading branch information
compiler-errors committed Mar 21, 2024
1 parent 08d8cd5 commit dae3c43
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 36 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/ty/error.rs
Expand Up @@ -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,
Expand Down
23 changes: 3 additions & 20 deletions compiler/rustc_middle/src/ty/mod.rs
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
16 changes: 1 addition & 15 deletions compiler/rustc_middle/src/ty/relate.rs
Expand Up @@ -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) }
}
}

Expand Down

0 comments on commit dae3c43

Please sign in to comment.