Skip to content

Commit f3ebf1e

Browse files
authored
Rollup merge of rust-lang#120516 - Nadrieril:cleanup-impls, r=compiler-errors
pattern_analysis: cleanup manual impls rust-lang#120420 introduced some unneeded manual impls. I remove them here. r? ```@Nilstrieb```
2 parents 6f24836 + 40402cb commit f3ebf1e

File tree

3 files changed

+4
-91
lines changed

3 files changed

+4
-91
lines changed

compiler/rustc_pattern_analysis/src/constructor.rs

+1-69
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,6 @@
151151
use std::cmp::{self, max, min, Ordering};
152152
use std::fmt;
153153
use std::iter::once;
154-
use std::mem;
155154

156155
use smallvec::SmallVec;
157156

@@ -648,6 +647,7 @@ impl OpaqueId {
648647
/// `specialize_constructor` returns the list of fields corresponding to a pattern, given a
649648
/// constructor. `Constructor::apply` reconstructs the pattern from a pair of `Constructor` and
650649
/// `Fields`.
650+
#[derive(Debug)]
651651
pub enum Constructor<Cx: TypeCx> {
652652
/// Tuples and structs.
653653
Struct,
@@ -717,74 +717,6 @@ impl<Cx: TypeCx> Clone for Constructor<Cx> {
717717
}
718718
}
719719

720-
impl<Cx: TypeCx> fmt::Debug for Constructor<Cx> {
721-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
722-
match self {
723-
Constructor::Struct => f.debug_tuple("Struct").finish(),
724-
Constructor::Variant(idx) => f.debug_tuple("Variant").field(idx).finish(),
725-
Constructor::Ref => f.debug_tuple("Ref").finish(),
726-
Constructor::Slice(slice) => f.debug_tuple("Slice").field(slice).finish(),
727-
Constructor::UnionField => f.debug_tuple("UnionField").finish(),
728-
Constructor::Bool(b) => f.debug_tuple("Bool").field(b).finish(),
729-
Constructor::IntRange(range) => f.debug_tuple("IntRange").field(range).finish(),
730-
Constructor::F32Range(lo, hi, end) => {
731-
f.debug_tuple("F32Range").field(lo).field(hi).field(end).finish()
732-
}
733-
Constructor::F64Range(lo, hi, end) => {
734-
f.debug_tuple("F64Range").field(lo).field(hi).field(end).finish()
735-
}
736-
Constructor::Str(value) => f.debug_tuple("Str").field(value).finish(),
737-
Constructor::Opaque(inner) => f.debug_tuple("Opaque").field(inner).finish(),
738-
Constructor::Or => f.debug_tuple("Or").finish(),
739-
Constructor::Wildcard => f.debug_tuple("Wildcard").finish(),
740-
Constructor::NonExhaustive => f.debug_tuple("NonExhaustive").finish(),
741-
Constructor::Hidden => f.debug_tuple("Hidden").finish(),
742-
Constructor::Missing => f.debug_tuple("Missing").finish(),
743-
}
744-
}
745-
}
746-
747-
impl<Cx: TypeCx> PartialEq for Constructor<Cx> {
748-
fn eq(&self, other: &Self) -> bool {
749-
(mem::discriminant(self) == mem::discriminant(other))
750-
&& match (self, other) {
751-
(Constructor::Struct, Constructor::Struct) => true,
752-
(Constructor::Variant(self_variant), Constructor::Variant(other_variant)) => {
753-
self_variant == other_variant
754-
}
755-
(Constructor::Ref, Constructor::Ref) => true,
756-
(Constructor::Slice(self_slice), Constructor::Slice(other_slice)) => {
757-
self_slice == other_slice
758-
}
759-
(Constructor::UnionField, Constructor::UnionField) => true,
760-
(Constructor::Bool(self_b), Constructor::Bool(other_b)) => self_b == other_b,
761-
(Constructor::IntRange(self_range), Constructor::IntRange(other_range)) => {
762-
self_range == other_range
763-
}
764-
(
765-
Constructor::F32Range(self_lo, self_hi, self_end),
766-
Constructor::F32Range(other_lo, other_hi, other_end),
767-
) => self_lo == other_lo && self_hi == other_hi && self_end == other_end,
768-
(
769-
Constructor::F64Range(self_lo, self_hi, self_end),
770-
Constructor::F64Range(other_lo, other_hi, other_end),
771-
) => self_lo == other_lo && self_hi == other_hi && self_end == other_end,
772-
(Constructor::Str(self_value), Constructor::Str(other_value)) => {
773-
self_value == other_value
774-
}
775-
(Constructor::Opaque(self_inner), Constructor::Opaque(other_inner)) => {
776-
self_inner == other_inner
777-
}
778-
(Constructor::Or, Constructor::Or) => true,
779-
(Constructor::Wildcard, Constructor::Wildcard) => true,
780-
(Constructor::NonExhaustive, Constructor::NonExhaustive) => true,
781-
(Constructor::Hidden, Constructor::Hidden) => true,
782-
(Constructor::Missing, Constructor::Missing) => true,
783-
_ => unreachable!(),
784-
}
785-
}
786-
}
787-
788720
impl<Cx: TypeCx> Constructor<Cx> {
789721
pub(crate) fn is_non_exhaustive(&self) -> bool {
790722
matches!(self, NonExhaustive)

compiler/rustc_pattern_analysis/src/pat.rs

+1-10
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,7 @@ impl<'p, Cx: TypeCx> fmt::Debug for PatOrWild<'p, Cx> {
297297

298298
/// Same idea as `DeconstructedPat`, except this is a fictitious pattern built up for diagnostics
299299
/// purposes. As such they don't use interning and can be cloned.
300+
#[derive(Debug)]
300301
pub struct WitnessPat<Cx: TypeCx> {
301302
ctor: Constructor<Cx>,
302303
pub(crate) fields: Vec<WitnessPat<Cx>>,
@@ -309,16 +310,6 @@ impl<Cx: TypeCx> Clone for WitnessPat<Cx> {
309310
}
310311
}
311312

312-
impl<Cx: TypeCx> fmt::Debug for WitnessPat<Cx> {
313-
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
314-
fmt.debug_struct("WitnessPat")
315-
.field("ctor", &self.ctor)
316-
.field("fields", &self.fields)
317-
.field("ty", &self.ty)
318-
.finish()
319-
}
320-
}
321-
322313
impl<Cx: TypeCx> WitnessPat<Cx> {
323314
pub(crate) fn new(ctor: Constructor<Cx>, fields: Vec<Self>, ty: Cx::Ty) -> Self {
324315
Self { ctor, fields, ty }

compiler/rustc_pattern_analysis/src/usefulness.rs

+2-12
Original file line numberDiff line numberDiff line change
@@ -1207,6 +1207,7 @@ impl<'p, Cx: TypeCx> fmt::Debug for Matrix<'p, Cx> {
12071207
/// The final `Pair(Some(_), true)` is then the resulting witness.
12081208
///
12091209
/// See the top of the file for more detailed explanations and examples.
1210+
#[derive(Debug)]
12101211
struct WitnessStack<Cx: TypeCx>(Vec<WitnessPat<Cx>>);
12111212

12121213
impl<Cx: TypeCx> Clone for WitnessStack<Cx> {
@@ -1215,12 +1216,6 @@ impl<Cx: TypeCx> Clone for WitnessStack<Cx> {
12151216
}
12161217
}
12171218

1218-
impl<Cx: TypeCx> fmt::Debug for WitnessStack<Cx> {
1219-
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
1220-
fmt.debug_tuple("WitnessStack").field(&self.0).finish()
1221-
}
1222-
}
1223-
12241219
impl<Cx: TypeCx> WitnessStack<Cx> {
12251220
/// Asserts that the witness contains a single pattern, and returns it.
12261221
fn single_pattern(self) -> WitnessPat<Cx> {
@@ -1265,6 +1260,7 @@ impl<Cx: TypeCx> WitnessStack<Cx> {
12651260
///
12661261
/// Just as the `Matrix` starts with a single column, by the end of the algorithm, this has a single
12671262
/// column, which contains the patterns that are missing for the match to be exhaustive.
1263+
#[derive(Debug)]
12681264
struct WitnessMatrix<Cx: TypeCx>(Vec<WitnessStack<Cx>>);
12691265

12701266
impl<Cx: TypeCx> Clone for WitnessMatrix<Cx> {
@@ -1273,12 +1269,6 @@ impl<Cx: TypeCx> Clone for WitnessMatrix<Cx> {
12731269
}
12741270
}
12751271

1276-
impl<Cx: TypeCx> fmt::Debug for WitnessMatrix<Cx> {
1277-
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
1278-
fmt.debug_tuple("WitnessMatrix").field(&self.0).finish()
1279-
}
1280-
}
1281-
12821272
impl<Cx: TypeCx> WitnessMatrix<Cx> {
12831273
/// New matrix with no witnesses.
12841274
fn empty() -> Self {

0 commit comments

Comments
 (0)