Skip to content

Commit

Permalink
remove PredicatePolarity and BoundConstness relate impls
Browse files Browse the repository at this point in the history
Also removes `TypeError::ConstnessMismatch`. It is unused.
  • Loading branch information
lcnr committed Oct 22, 2024
1 parent 196fdf1 commit 00266ee
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 40 deletions.
3 changes: 0 additions & 3 deletions compiler/rustc_middle/src/ty/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ impl<'tcx> TypeError<'tcx> {
TypeError::CyclicTy(_) => "cyclic type of infinite size".into(),
TypeError::CyclicConst(_) => "encountered a self-referencing constant".into(),
TypeError::Mismatch => "types differ".into(),
TypeError::ConstnessMismatch(values) => {
format!("expected {} bound, found {} bound", values.expected, values.found).into()
}
TypeError::PolarityMismatch(values) => {
format!("expected {} polarity, found {} polarity", values.expected, values.found)
.into()
Expand Down
9 changes: 4 additions & 5 deletions compiler/rustc_type_ir/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ impl<T> ExpectedFound<T> {
#[cfg_attr(feature = "nightly", rustc_pass_by_value)]
pub enum TypeError<I: Interner> {
Mismatch,
ConstnessMismatch(ExpectedFound<ty::BoundConstness>),
PolarityMismatch(ExpectedFound<ty::PredicatePolarity>),
PolarityMismatch(#[type_visitable(ignore)] ExpectedFound<ty::PredicatePolarity>),
SafetyMismatch(#[type_visitable(ignore)] ExpectedFound<I::Safety>),
AbiMismatch(#[type_visitable(ignore)] ExpectedFound<I::Abi>),
Mutability,
Expand Down Expand Up @@ -73,9 +72,9 @@ impl<I: Interner> TypeError<I> {
pub fn must_include_note(self) -> bool {
use self::TypeError::*;
match self {
CyclicTy(_) | CyclicConst(_) | SafetyMismatch(_) | ConstnessMismatch(_)
| PolarityMismatch(_) | Mismatch | AbiMismatch(_) | FixedArraySize(_)
| ArgumentSorts(..) | Sorts(_) | VariadicMismatch(_) | TargetFeatureCast(_) => false,
CyclicTy(_) | CyclicConst(_) | SafetyMismatch(_) | PolarityMismatch(_) | Mismatch
| AbiMismatch(_) | FixedArraySize(_) | ArgumentSorts(..) | Sorts(_)
| VariadicMismatch(_) | TargetFeatureCast(_) => false,

Mutability
| ArgumentMutability(_)
Expand Down
39 changes: 7 additions & 32 deletions compiler/rustc_type_ir/src/relate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,20 +223,6 @@ impl<I: Interner> Relate<I> for ty::FnSig<I> {
}
}

impl<I: Interner> Relate<I> for ty::BoundConstness {
fn relate<R: TypeRelation<I>>(
_relation: &mut R,
a: ty::BoundConstness,
b: ty::BoundConstness,
) -> RelateResult<I, ty::BoundConstness> {
if a != b {
Err(TypeError::ConstnessMismatch(ExpectedFound::new(true, a, b)))
} else {
Ok(a)
}
}
}

impl<I: Interner> Relate<I> for ty::AliasTy<I> {
fn relate<R: TypeRelation<I>>(
relation: &mut R,
Expand Down Expand Up @@ -664,29 +650,18 @@ impl<I: Interner, T: Relate<I>> Relate<I> for ty::Binder<I, T> {
}
}

impl<I: Interner> Relate<I> for ty::PredicatePolarity {
fn relate<R: TypeRelation<I>>(
_relation: &mut R,
a: ty::PredicatePolarity,
b: ty::PredicatePolarity,
) -> RelateResult<I, ty::PredicatePolarity> {
if a != b {
Err(TypeError::PolarityMismatch(ExpectedFound::new(true, a, b)))
} else {
Ok(a)
}
}
}

impl<I: Interner> Relate<I> for ty::TraitPredicate<I> {
fn relate<R: TypeRelation<I>>(
relation: &mut R,
a: ty::TraitPredicate<I>,
b: ty::TraitPredicate<I>,
) -> RelateResult<I, ty::TraitPredicate<I>> {
Ok(ty::TraitPredicate {
trait_ref: relation.relate(a.trait_ref, b.trait_ref)?,
polarity: relation.relate(a.polarity, b.polarity)?,
})
let trait_ref = relation.relate(a.trait_ref, b.trait_ref)?;
if a.polarity != b.polarity {
return Err(TypeError::PolarityMismatch(ExpectedFound::new(
true, a.polarity, b.polarity,
)));
}
Ok(ty::TraitPredicate { trait_ref, polarity: a.polarity })
}
}

0 comments on commit 00266ee

Please sign in to comment.