Remove `PatKind::Slice`

This commit is contained in:
Zalathar 2024-08-03 21:02:00 +10:00
parent 2b6f4386eb
commit ec1483bf2e
2 changed files with 8 additions and 17 deletions

View File

@ -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 => {

View File

@ -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,