summary refs log tree commit diff
path: root/compiler/rustc_pattern_analysis
diff options
context:
space:
mode:
authorZalathar <Zalathar@users.noreply.github.com>2024-08-02 20:09:12 +1000
committerZalathar <Zalathar@users.noreply.github.com>2024-08-07 20:52:46 +1000
commite98e19e49108b6e49e452c3bd22c1aeccd43e507 (patch)
tree8326d4c341fd0a72402ca6ba5cd0ffc54f4f1722 /compiler/rustc_pattern_analysis
parent4cd800503f0c0ba3c26f30c98aff755be6b9be43 (diff)
downloadrust-e98e19e49108b6e49e452c3bd22c1aeccd43e507.tar.gz
rust-e98e19e49108b6e49e452c3bd22c1aeccd43e507.zip
Replace an unnecessary slice pattern with `has_dot_dot: bool`
Diffstat (limited to 'compiler/rustc_pattern_analysis')
-rw-r--r--compiler/rustc_pattern_analysis/src/rustc.rs5
-rw-r--r--compiler/rustc_pattern_analysis/src/rustc/print.rs19
2 files changed, 10 insertions, 14 deletions
diff --git a/compiler/rustc_pattern_analysis/src/rustc.rs b/compiler/rustc_pattern_analysis/src/rustc.rs
index 7fe2c14a745..f27c279912f 100644
--- a/compiler/rustc_pattern_analysis/src/rustc.rs
+++ b/compiler/rustc_pattern_analysis/src/rustc.rs
@@ -872,7 +872,7 @@ impl<'p, 'tcx: 'p> RustcPatCtxt<'p, 'tcx> {
                 match slice.kind {
                     SliceKind::FixedLen(_) => PatKind::Slice {
                         prefix: subpatterns.collect(),
-                        slice: None,
+                        has_dot_dot: false,
                         suffix: Box::new([]),
                     },
                     SliceKind::VarLen(prefix, _) => {
@@ -893,10 +893,9 @@ impl<'p, 'tcx: 'p> RustcPatCtxt<'p, 'tcx> {
                             }
                         }
                         let suffix: Box<[_]> = subpatterns.collect();
-                        let wild = Pat { ty: pat.ty().inner(), kind: PatKind::Wild };
                         PatKind::Slice {
                             prefix: prefix.into_boxed_slice(),
-                            slice: Some(Box::new(wild)),
+                            has_dot_dot: true,
                             suffix,
                         }
                     }
diff --git a/compiler/rustc_pattern_analysis/src/rustc/print.rs b/compiler/rustc_pattern_analysis/src/rustc/print.rs
index d14233ee024..e7568b9e2bd 100644
--- a/compiler/rustc_pattern_analysis/src/rustc/print.rs
+++ b/compiler/rustc_pattern_analysis/src/rustc/print.rs
@@ -50,7 +50,9 @@ pub(crate) enum PatKind<'tcx> {
 
     Slice {
         prefix: Box<[Box<Pat<'tcx>>]>,
-        slice: Option<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>>]>,
     },
 
@@ -68,8 +70,8 @@ impl<'tcx> fmt::Display for Pat<'tcx> {
             PatKind::Deref { ref subpattern } => write_ref_like(f, self.ty, subpattern),
             PatKind::Constant { value } => write!(f, "{value}"),
             PatKind::Range(ref range) => write!(f, "{range}"),
-            PatKind::Slice { ref prefix, ref slice, ref suffix } => {
-                write_slice_like(f, prefix, slice, suffix)
+            PatKind::Slice { ref prefix, has_dot_dot, ref suffix } => {
+                write_slice_like(f, prefix, has_dot_dot, suffix)
             }
         }
     }
@@ -194,7 +196,7 @@ fn write_ref_like<'tcx>(
 fn write_slice_like<'tcx>(
     f: &mut impl fmt::Write,
     prefix: &[Box<Pat<'tcx>>],
-    slice: &Option<Box<Pat<'tcx>>>,
+    has_dot_dot: bool,
     suffix: &[Box<Pat<'tcx>>],
 ) -> fmt::Result {
     let mut start_or_comma = start_or_comma();
@@ -202,13 +204,8 @@ fn write_slice_like<'tcx>(
     for p in prefix.iter() {
         write!(f, "{}{}", start_or_comma(), p)?;
     }
-    if let Some(ref slice) = *slice {
-        write!(f, "{}", start_or_comma())?;
-        match slice.kind {
-            PatKind::Wild => {}
-            _ => write!(f, "{slice}")?,
-        }
-        write!(f, "..")?;
+    if has_dot_dot {
+        write!(f, "{}..", start_or_comma())?;
     }
     for p in suffix.iter() {
         write!(f, "{}{}", start_or_comma(), p)?;