From 15b473451cce5237ccff6cad85836ecf203475e8 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Wed, 31 Jan 2024 00:58:22 +0100 Subject: [PATCH 1/2] Remove unused `Constructor: PartialEq` impl --- .../rustc_pattern_analysis/src/constructor.rs | 42 ------------------- 1 file changed, 42 deletions(-) diff --git a/compiler/rustc_pattern_analysis/src/constructor.rs b/compiler/rustc_pattern_analysis/src/constructor.rs index 4996015f86345..3211d6a4cfeaa 100644 --- a/compiler/rustc_pattern_analysis/src/constructor.rs +++ b/compiler/rustc_pattern_analysis/src/constructor.rs @@ -151,7 +151,6 @@ use std::cmp::{self, max, min, Ordering}; use std::fmt; use std::iter::once; -use std::mem; use smallvec::SmallVec; @@ -745,47 +744,6 @@ impl fmt::Debug for Constructor { } } -impl PartialEq for Constructor { - fn eq(&self, other: &Self) -> bool { - (mem::discriminant(self) == mem::discriminant(other)) - && match (self, other) { - (Constructor::Struct, Constructor::Struct) => true, - (Constructor::Variant(self_variant), Constructor::Variant(other_variant)) => { - self_variant == other_variant - } - (Constructor::Ref, Constructor::Ref) => true, - (Constructor::Slice(self_slice), Constructor::Slice(other_slice)) => { - self_slice == other_slice - } - (Constructor::UnionField, Constructor::UnionField) => true, - (Constructor::Bool(self_b), Constructor::Bool(other_b)) => self_b == other_b, - (Constructor::IntRange(self_range), Constructor::IntRange(other_range)) => { - self_range == other_range - } - ( - Constructor::F32Range(self_lo, self_hi, self_end), - Constructor::F32Range(other_lo, other_hi, other_end), - ) => self_lo == other_lo && self_hi == other_hi && self_end == other_end, - ( - Constructor::F64Range(self_lo, self_hi, self_end), - Constructor::F64Range(other_lo, other_hi, other_end), - ) => self_lo == other_lo && self_hi == other_hi && self_end == other_end, - (Constructor::Str(self_value), Constructor::Str(other_value)) => { - self_value == other_value - } - (Constructor::Opaque(self_inner), Constructor::Opaque(other_inner)) => { - self_inner == other_inner - } - (Constructor::Or, Constructor::Or) => true, - (Constructor::Wildcard, Constructor::Wildcard) => true, - (Constructor::NonExhaustive, Constructor::NonExhaustive) => true, - (Constructor::Hidden, Constructor::Hidden) => true, - (Constructor::Missing, Constructor::Missing) => true, - _ => unreachable!(), - } - } -} - impl Constructor { pub(crate) fn is_non_exhaustive(&self) -> bool { matches!(self, NonExhaustive) From 40402cbadad4f7df9ab7e2f3089a5b038d19f586 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Wed, 31 Jan 2024 01:29:21 +0100 Subject: [PATCH 2/2] Manual `Debug` impls are not needed since `TypeCx: Debug` --- .../rustc_pattern_analysis/src/constructor.rs | 28 +------------------ compiler/rustc_pattern_analysis/src/pat.rs | 11 +------- .../rustc_pattern_analysis/src/usefulness.rs | 14 ++-------- 3 files changed, 4 insertions(+), 49 deletions(-) diff --git a/compiler/rustc_pattern_analysis/src/constructor.rs b/compiler/rustc_pattern_analysis/src/constructor.rs index 3211d6a4cfeaa..8fc826f403e47 100644 --- a/compiler/rustc_pattern_analysis/src/constructor.rs +++ b/compiler/rustc_pattern_analysis/src/constructor.rs @@ -648,6 +648,7 @@ impl OpaqueId { /// `specialize_constructor` returns the list of fields corresponding to a pattern, given a /// constructor. `Constructor::apply` reconstructs the pattern from a pair of `Constructor` and /// `Fields`. +#[derive(Debug)] pub enum Constructor { /// Tuples and structs. Struct, @@ -717,33 +718,6 @@ impl Clone for Constructor { } } -impl fmt::Debug for Constructor { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - match self { - Constructor::Struct => f.debug_tuple("Struct").finish(), - Constructor::Variant(idx) => f.debug_tuple("Variant").field(idx).finish(), - Constructor::Ref => f.debug_tuple("Ref").finish(), - Constructor::Slice(slice) => f.debug_tuple("Slice").field(slice).finish(), - Constructor::UnionField => f.debug_tuple("UnionField").finish(), - Constructor::Bool(b) => f.debug_tuple("Bool").field(b).finish(), - Constructor::IntRange(range) => f.debug_tuple("IntRange").field(range).finish(), - Constructor::F32Range(lo, hi, end) => { - f.debug_tuple("F32Range").field(lo).field(hi).field(end).finish() - } - Constructor::F64Range(lo, hi, end) => { - f.debug_tuple("F64Range").field(lo).field(hi).field(end).finish() - } - Constructor::Str(value) => f.debug_tuple("Str").field(value).finish(), - Constructor::Opaque(inner) => f.debug_tuple("Opaque").field(inner).finish(), - Constructor::Or => f.debug_tuple("Or").finish(), - Constructor::Wildcard => f.debug_tuple("Wildcard").finish(), - Constructor::NonExhaustive => f.debug_tuple("NonExhaustive").finish(), - Constructor::Hidden => f.debug_tuple("Hidden").finish(), - Constructor::Missing => f.debug_tuple("Missing").finish(), - } - } -} - impl Constructor { pub(crate) fn is_non_exhaustive(&self) -> bool { matches!(self, NonExhaustive) diff --git a/compiler/rustc_pattern_analysis/src/pat.rs b/compiler/rustc_pattern_analysis/src/pat.rs index d476766d466f2..3d9da16344762 100644 --- a/compiler/rustc_pattern_analysis/src/pat.rs +++ b/compiler/rustc_pattern_analysis/src/pat.rs @@ -298,6 +298,7 @@ impl<'p, Cx: TypeCx> fmt::Debug for PatOrWild<'p, Cx> { /// Same idea as `DeconstructedPat`, except this is a fictitious pattern built up for diagnostics /// purposes. As such they don't use interning and can be cloned. +#[derive(Debug)] pub struct WitnessPat { ctor: Constructor, pub(crate) fields: Vec>, @@ -310,16 +311,6 @@ impl Clone for WitnessPat { } } -impl fmt::Debug for WitnessPat { - fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { - fmt.debug_struct("WitnessPat") - .field("ctor", &self.ctor) - .field("fields", &self.fields) - .field("ty", &self.ty) - .finish() - } -} - impl WitnessPat { pub(crate) fn new(ctor: Constructor, fields: Vec, ty: Cx::Ty) -> Self { Self { ctor, fields, ty } diff --git a/compiler/rustc_pattern_analysis/src/usefulness.rs b/compiler/rustc_pattern_analysis/src/usefulness.rs index b15de1c0ca9d7..a8d0c2e67df8b 100644 --- a/compiler/rustc_pattern_analysis/src/usefulness.rs +++ b/compiler/rustc_pattern_analysis/src/usefulness.rs @@ -1198,6 +1198,7 @@ impl<'p, Cx: TypeCx> fmt::Debug for Matrix<'p, Cx> { /// The final `Pair(Some(_), true)` is then the resulting witness. /// /// See the top of the file for more detailed explanations and examples. +#[derive(Debug)] struct WitnessStack(Vec>); impl Clone for WitnessStack { @@ -1206,12 +1207,6 @@ impl Clone for WitnessStack { } } -impl fmt::Debug for WitnessStack { - fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { - fmt.debug_tuple("WitnessStack").field(&self.0).finish() - } -} - impl WitnessStack { /// Asserts that the witness contains a single pattern, and returns it. fn single_pattern(self) -> WitnessPat { @@ -1256,6 +1251,7 @@ impl WitnessStack { /// /// Just as the `Matrix` starts with a single column, by the end of the algorithm, this has a single /// column, which contains the patterns that are missing for the match to be exhaustive. +#[derive(Debug)] struct WitnessMatrix(Vec>); impl Clone for WitnessMatrix { @@ -1264,12 +1260,6 @@ impl Clone for WitnessMatrix { } } -impl fmt::Debug for WitnessMatrix { - fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { - fmt.debug_tuple("WitnessMatrix").field(&self.0).finish() - } -} - impl WitnessMatrix { /// New matrix with no witnesses. fn empty() -> Self {