summary refs log tree commit diff
path: root/compiler/rustc_pattern_analysis/src
diff options
context:
space:
mode:
authorZalathar <Zalathar@users.noreply.github.com>2024-08-03 21:02:00 +1000
committerZalathar <Zalathar@users.noreply.github.com>2024-08-11 19:57:30 +1000
commitec1483bf2e317b4a8d073881c3e942f7a011ff1a (patch)
treece7410a6c2b0f289ac9b7ed570e4f5c15b4fb87b /compiler/rustc_pattern_analysis/src
parent2b6f4386ebdedd62a093577dafe5082e4f63b316 (diff)
downloadrust-ec1483bf2e317b4a8d073881c3e942f7a011ff1a.tar.gz
rust-ec1483bf2e317b4a8d073881c3e942f7a011ff1a.zip
Remove `PatKind::Slice`
Diffstat (limited to 'compiler/rustc_pattern_analysis/src')
-rw-r--r--compiler/rustc_pattern_analysis/src/rustc.rs8
-rw-r--r--compiler/rustc_pattern_analysis/src/rustc/print.rs17
2 files changed, 8 insertions, 17 deletions
diff --git a/compiler/rustc_pattern_analysis/src/rustc.rs b/compiler/rustc_pattern_analysis/src/rustc.rs
index d7c14348b1b..653097314f7 100644
--- a/compiler/rustc_pattern_analysis/src/rustc.rs
+++ b/compiler/rustc_pattern_analysis/src/rustc.rs
@@ -897,10 +897,12 @@ impl<'p, 'tcx: 'p> RustcPatCtxt<'p, 'tcx> {
                     }
                 }
 
-                let prefix = prefix.iter().map(hoist).collect();
-                let suffix = suffix.iter().map(hoist).collect();
+                let prefix = prefix.iter().map(hoist).collect::<Vec<_>>();
+                let suffix = suffix.iter().map(hoist).collect::<Vec<_>>();
 
-                PatKind::Slice { prefix, has_dot_dot, suffix }
+                let mut s = String::new();
+                print::write_slice_like(&mut s, &prefix, has_dot_dot, &suffix).unwrap();
+                PatKind::Print(s)
             }
             Never if self.tcx.features().never_patterns => PatKind::Never,
             Never | Wildcard | NonExhaustive | Hidden | PrivateUninhabited => {
diff --git a/compiler/rustc_pattern_analysis/src/rustc/print.rs b/compiler/rustc_pattern_analysis/src/rustc/print.rs
index fab71b421f8..adda21a8b25 100644
--- a/compiler/rustc_pattern_analysis/src/rustc/print.rs
+++ b/compiler/rustc_pattern_analysis/src/rustc/print.rs
@@ -27,19 +27,11 @@ pub(crate) struct FieldPat<'tcx> {
 pub(crate) struct Pat<'tcx> {
     #[allow(dead_code)]
     pub(crate) ty: Ty<'tcx>,
-    pub(crate) kind: PatKind<'tcx>,
+    pub(crate) kind: PatKind,
 }
 
 #[derive(Clone, Debug)]
-pub(crate) enum PatKind<'tcx> {
-    Slice {
-        prefix: Box<[Box<Pat<'tcx>>]>,
-        /// True if this slice-like pattern should include a `..` between the
-        /// prefix and suffix.
-        has_dot_dot: bool,
-        suffix: Box<[Box<Pat<'tcx>>]>,
-    },
-
+pub(crate) enum PatKind {
     Never,
 
     Print(String),
@@ -49,9 +41,6 @@ impl<'tcx> fmt::Display for Pat<'tcx> {
     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
         match self.kind {
             PatKind::Never => write!(f, "!"),
-            PatKind::Slice { ref prefix, has_dot_dot, ref suffix } => {
-                write_slice_like(f, prefix, has_dot_dot, suffix)
-            }
             PatKind::Print(ref string) => write!(f, "{string}"),
         }
     }
@@ -173,7 +162,7 @@ pub(crate) fn write_ref_like<'tcx>(
     write!(f, "{subpattern}")
 }
 
-fn write_slice_like<'tcx>(
+pub(crate) fn write_slice_like<'tcx>(
     f: &mut impl fmt::Write,
     prefix: &[Box<Pat<'tcx>>],
     has_dot_dot: bool,