From 00266eeaa5957f0dde0b17f2823fd4b4ea6996c2 Mon Sep 17 00:00:00 2001 From: lcnr Date: Wed, 23 Oct 2024 00:52:37 +0200 Subject: [PATCH] remove `PredicatePolarity` and `BoundConstness` relate impls Also removes `TypeError::ConstnessMismatch`. It is unused. --- compiler/rustc_middle/src/ty/error.rs | 3 --- compiler/rustc_type_ir/src/error.rs | 9 +++---- compiler/rustc_type_ir/src/relate.rs | 39 +++++---------------------- 3 files changed, 11 insertions(+), 40 deletions(-) diff --git a/compiler/rustc_middle/src/ty/error.rs b/compiler/rustc_middle/src/ty/error.rs index b02eff3bfd6..c49824bb418 100644 --- a/compiler/rustc_middle/src/ty/error.rs +++ b/compiler/rustc_middle/src/ty/error.rs @@ -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() diff --git a/compiler/rustc_type_ir/src/error.rs b/compiler/rustc_type_ir/src/error.rs index 72501945721..cdff77f742d 100644 --- a/compiler/rustc_type_ir/src/error.rs +++ b/compiler/rustc_type_ir/src/error.rs @@ -27,8 +27,7 @@ impl ExpectedFound { #[cfg_attr(feature = "nightly", rustc_pass_by_value)] pub enum TypeError { Mismatch, - ConstnessMismatch(ExpectedFound), - PolarityMismatch(ExpectedFound), + PolarityMismatch(#[type_visitable(ignore)] ExpectedFound), SafetyMismatch(#[type_visitable(ignore)] ExpectedFound), AbiMismatch(#[type_visitable(ignore)] ExpectedFound), Mutability, @@ -73,9 +72,9 @@ impl TypeError { 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(_) diff --git a/compiler/rustc_type_ir/src/relate.rs b/compiler/rustc_type_ir/src/relate.rs index ccb8e9fcf7c..ad17911830b 100644 --- a/compiler/rustc_type_ir/src/relate.rs +++ b/compiler/rustc_type_ir/src/relate.rs @@ -223,20 +223,6 @@ impl Relate for ty::FnSig { } } -impl Relate for ty::BoundConstness { - fn relate>( - _relation: &mut R, - a: ty::BoundConstness, - b: ty::BoundConstness, - ) -> RelateResult { - if a != b { - Err(TypeError::ConstnessMismatch(ExpectedFound::new(true, a, b))) - } else { - Ok(a) - } - } -} - impl Relate for ty::AliasTy { fn relate>( relation: &mut R, @@ -664,29 +650,18 @@ impl> Relate for ty::Binder { } } -impl Relate for ty::PredicatePolarity { - fn relate>( - _relation: &mut R, - a: ty::PredicatePolarity, - b: ty::PredicatePolarity, - ) -> RelateResult { - if a != b { - Err(TypeError::PolarityMismatch(ExpectedFound::new(true, a, b))) - } else { - Ok(a) - } - } -} - impl Relate for ty::TraitPredicate { fn relate>( relation: &mut R, a: ty::TraitPredicate, b: ty::TraitPredicate, ) -> RelateResult> { - 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 }) } }