diff --git a/compiler/rustc_mir_build/src/thir/pattern/usefulness.rs b/compiler/rustc_mir_build/src/thir/pattern/usefulness.rs index 4824794d581..80e9bcbde77 100644 --- a/compiler/rustc_mir_build/src/thir/pattern/usefulness.rs +++ b/compiler/rustc_mir_build/src/thir/pattern/usefulness.rs @@ -301,7 +301,7 @@ use rustc_span::Span; use smallvec::{smallvec, SmallVec}; use std::fmt; -use std::iter::{FromIterator, IntoIterator}; +use std::iter::IntoIterator; use std::lazy::OnceCell; crate struct MatchCheckCtxt<'a, 'tcx> { @@ -489,15 +489,6 @@ impl<'p, 'tcx> PartialEq for PatStack<'p, 'tcx> { } } -impl<'p, 'tcx> FromIterator<&'p Pat<'tcx>> for PatStack<'p, 'tcx> { - fn from_iter(iter: T) -> Self - where - T: IntoIterator>, - { - Self::from_vec(iter.into_iter().collect()) - } -} - /// Pretty-printing for matrix row. impl<'p, 'tcx> fmt::Debug for PatStack<'p, 'tcx> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { @@ -565,11 +556,14 @@ impl<'p, 'tcx> Matrix<'p, 'tcx> { ctor: &Constructor<'tcx>, ctor_wild_subpatterns: &Fields<'p, 'tcx>, ) -> Matrix<'p, 'tcx> { - self.patterns - .iter() - .filter(|r| ctor.is_covered_by(pcx, r.head_ctor(pcx.cx))) - .map(|r| r.pop_head_constructor(ctor_wild_subpatterns)) - .collect() + let mut matrix = Matrix::empty(); + for row in &self.patterns { + if ctor.is_covered_by(pcx, row.head_ctor(pcx.cx)) { + let new_row = row.pop_head_constructor(ctor_wild_subpatterns); + matrix.push(new_row); + } + } + matrix } } @@ -609,20 +603,6 @@ impl<'p, 'tcx> fmt::Debug for Matrix<'p, 'tcx> { } } -impl<'p, 'tcx> FromIterator> for Matrix<'p, 'tcx> { - fn from_iter(iter: T) -> Self - where - T: IntoIterator>, - { - let mut matrix = Matrix::empty(); - for x in iter { - // Using `push` ensures we correctly expand or-patterns. - matrix.push(x); - } - matrix - } -} - /// Given a pattern or a pattern-stack, this struct captures a set of its subpatterns. We use that /// to track reachable sub-patterns arising from or-patterns. In the absence of or-patterns this /// will always be either `Empty` (the whole pattern is unreachable) or `Full` (the whole pattern