mirror of https://github.com/rust-lang/rust.git
Further simplifications
This commit is contained in:
parent
560c6cc602
commit
d677a2d73b
|
@ -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,
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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) }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue