1 // Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
13 use rustc::middle::const_val::{ConstEvalErr, ConstVal};
14 use rustc::mir::{Field, BorrowKind, Mutability};
15 use rustc::ty::{self, TyCtxt, AdtDef, Ty, Region};
16 use rustc::ty::subst::{Substs, Kind};
17 use rustc::hir::{self, PatKind, RangeEnd};
18 use rustc::hir::def::{Def, CtorKind};
19 use rustc::hir::pat_util::EnumerateAndAdjustIterator;
21 use rustc_data_structures::indexed_vec::Idx;
28 #[derive(Clone, Debug)]
29 pub enum PatternError<'tcx> {
30 StaticInPattern(Span),
31 ConstEval(ConstEvalErr<'tcx>),
34 #[derive(Copy, Clone, Debug)]
35 pub enum BindingMode<'tcx> {
37 ByRef(Region<'tcx>, BorrowKind),
40 #[derive(Clone, Debug)]
41 pub struct FieldPattern<'tcx> {
43 pub pattern: Pattern<'tcx>,
46 #[derive(Clone, Debug)]
47 pub struct Pattern<'tcx> {
50 pub kind: Box<PatternKind<'tcx>>,
53 #[derive(Clone, Debug)]
54 pub enum PatternKind<'tcx> {
57 /// x, ref x, x @ P, etc
59 mutability: Mutability,
61 mode: BindingMode<'tcx>,
64 subpattern: Option<Pattern<'tcx>>,
67 /// Foo(...) or Foo{...} or Foo, where `Foo` is a variant name from an adt with >1 variants
69 adt_def: &'tcx AdtDef,
70 substs: &'tcx Substs<'tcx>,
72 subpatterns: Vec<FieldPattern<'tcx>>,
75 /// (...), Foo(...), Foo{...}, or Foo, where `Foo` is a variant name from an adt with 1 variant
77 subpatterns: Vec<FieldPattern<'tcx>>,
80 /// box P, &P, &mut P, etc
82 subpattern: Pattern<'tcx>,
86 value: ConstVal<'tcx>,
95 /// matches against a slice, checking the length and extracting elements
97 prefix: Vec<Pattern<'tcx>>,
98 slice: Option<Pattern<'tcx>>,
99 suffix: Vec<Pattern<'tcx>>,
102 /// fixed match against an array, irrefutable
104 prefix: Vec<Pattern<'tcx>>,
105 slice: Option<Pattern<'tcx>>,
106 suffix: Vec<Pattern<'tcx>>,
110 fn print_const_val(value: &ConstVal, f: &mut fmt::Formatter) -> fmt::Result {
112 ConstVal::Float(ref x) => write!(f, "{}", x),
113 ConstVal::Integral(ref i) => write!(f, "{}", i),
114 ConstVal::Str(ref s) => write!(f, "{:?}", &s[..]),
115 ConstVal::ByteStr(ref b) => write!(f, "{:?}", &b[..]),
116 ConstVal::Bool(b) => write!(f, "{:?}", b),
117 ConstVal::Char(c) => write!(f, "{:?}", c),
118 ConstVal::Variant(_) |
119 ConstVal::Struct(_) |
121 ConstVal::Function(..) |
122 ConstVal::Array(..) |
123 ConstVal::Repeat(..) => bug!("{:?} not printable in a pattern", value)
127 impl<'tcx> fmt::Display for Pattern<'tcx> {
128 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
130 PatternKind::Wild => write!(f, "_"),
131 PatternKind::Binding { mutability, name, mode, ref subpattern, .. } => {
132 let is_mut = match mode {
133 BindingMode::ByValue => mutability == Mutability::Mut,
134 BindingMode::ByRef(_, bk) => {
136 bk == BorrowKind::Mut
142 write!(f, "{}", name)?;
143 if let Some(ref subpattern) = *subpattern {
144 write!(f, " @ {}", subpattern)?;
148 PatternKind::Variant { ref subpatterns, .. } |
149 PatternKind::Leaf { ref subpatterns } => {
150 let variant = match *self.kind {
151 PatternKind::Variant { adt_def, variant_index, .. } => {
152 Some(&adt_def.variants[variant_index])
154 _ => if let ty::TyAdt(adt, _) = self.ty.sty {
155 if adt.is_univariant() {
156 Some(&adt.variants[0])
165 let mut first = true;
166 let mut start_or_continue = || if first { first = false; "" } else { ", " };
168 if let Some(variant) = variant {
169 write!(f, "{}", variant.name)?;
171 // Only for TyAdt we can have `S {...}`,
172 // which we handle separately here.
173 if variant.ctor_kind == CtorKind::Fictive {
177 for p in subpatterns {
178 if let PatternKind::Wild = *p.pattern.kind {
181 let name = variant.fields[p.field.index()].name;
182 write!(f, "{}{}: {}", start_or_continue(), name, p.pattern)?;
186 if printed < variant.fields.len() {
187 write!(f, "{}..", start_or_continue())?;
190 return write!(f, " }}");
194 let num_fields = variant.map_or(subpatterns.len(), |v| v.fields.len());
195 if num_fields != 0 || variant.is_none() {
197 for i in 0..num_fields {
198 write!(f, "{}", start_or_continue())?;
200 // Common case: the field is where we expect it.
201 if let Some(p) = subpatterns.get(i) {
202 if p.field.index() == i {
203 write!(f, "{}", p.pattern)?;
208 // Otherwise, we have to go looking for it.
209 if let Some(p) = subpatterns.iter().find(|p| p.field.index() == i) {
210 write!(f, "{}", p.pattern)?;
220 PatternKind::Deref { ref subpattern } => {
222 ty::TyAdt(def, _) if def.is_box() => write!(f, "box ")?,
223 ty::TyRef(_, mt) => {
225 if mt.mutbl == hir::MutMutable {
229 _ => bug!("{} is a bad Deref pattern type", self.ty)
231 write!(f, "{}", subpattern)
233 PatternKind::Constant { ref value } => {
234 print_const_val(value, f)
236 PatternKind::Range { ref lo, ref hi, ref end } => {
237 print_const_val(lo, f)?;
239 RangeEnd::Included => write!(f, "...")?,
240 RangeEnd::Excluded => write!(f, "..")?,
242 print_const_val(hi, f)
244 PatternKind::Slice { ref prefix, ref slice, ref suffix } |
245 PatternKind::Array { ref prefix, ref slice, ref suffix } => {
246 let mut first = true;
247 let mut start_or_continue = || if first { first = false; "" } else { ", " };
250 write!(f, "{}{}", start_or_continue(), p)?;
252 if let Some(ref slice) = *slice {
253 write!(f, "{}", start_or_continue())?;
255 PatternKind::Wild => {}
256 _ => write!(f, "{}", slice)?
261 write!(f, "{}{}", start_or_continue(), p)?;
269 pub struct PatternContext<'a, 'gcx: 'tcx, 'tcx: 'a> {
270 pub tcx: TyCtxt<'a, 'gcx, 'tcx>,
271 pub tables: &'a ty::TypeckTables<'gcx>,
272 pub errors: Vec<PatternError<'tcx>>,
275 impl<'a, 'gcx, 'tcx> Pattern<'tcx> {
276 pub fn from_hir(tcx: TyCtxt<'a, 'gcx, 'tcx>,
277 tables: &'a ty::TypeckTables<'gcx>,
278 pat: &hir::Pat) -> Self {
279 let mut pcx = PatternContext::new(tcx, tables);
280 let result = pcx.lower_pattern(pat);
281 if !pcx.errors.is_empty() {
282 span_bug!(pat.span, "encountered errors lowering pattern: {:?}", pcx.errors)
284 debug!("Pattern::from_hir({:?}) = {:?}", pat, result);
289 impl<'a, 'gcx, 'tcx> PatternContext<'a, 'gcx, 'tcx> {
290 pub fn new(tcx: TyCtxt<'a, 'gcx, 'tcx>, tables: &'a ty::TypeckTables<'gcx>) -> Self {
291 PatternContext { tcx: tcx, tables: tables, errors: vec![] }
294 pub fn lower_pattern(&mut self, pat: &hir::Pat) -> Pattern<'tcx> {
295 let mut ty = self.tables.node_id_to_type(pat.id);
297 let kind = match pat.node {
298 PatKind::Wild => PatternKind::Wild,
300 PatKind::Lit(ref value) => self.lower_lit(value),
302 PatKind::Range(ref lo, ref hi, ref end) => {
303 match (self.lower_lit(lo), self.lower_lit(hi)) {
304 (PatternKind::Constant { value: lo },
305 PatternKind::Constant { value: hi }) => {
306 PatternKind::Range { lo: lo, hi: hi, end: end.clone() }
308 _ => PatternKind::Wild
312 PatKind::Path(ref qpath) => {
313 return self.lower_path(qpath, pat.id, pat.id, pat.span);
316 PatKind::Ref(ref subpattern, _) |
317 PatKind::Box(ref subpattern) => {
318 PatternKind::Deref { subpattern: self.lower_pattern(subpattern) }
321 PatKind::Slice(ref prefix, ref slice, ref suffix) => {
322 let ty = self.tables.node_id_to_type(pat.id);
326 subpattern: Pattern {
329 kind: Box::new(self.slice_or_array_pattern(
330 pat.span, mt.ty, prefix, slice, suffix))
336 self.slice_or_array_pattern(pat.span, ty, prefix, slice, suffix),
341 "unexpanded type for vector pattern: {:?}",
346 PatKind::Tuple(ref subpatterns, ddpos) => {
347 let ty = self.tables.node_id_to_type(pat.id);
349 ty::TyTuple(ref tys, _) => {
352 .enumerate_and_adjust(tys.len(), ddpos)
353 .map(|(i, subpattern)| FieldPattern {
354 field: Field::new(i),
355 pattern: self.lower_pattern(subpattern)
359 PatternKind::Leaf { subpatterns: subpatterns }
362 ref sty => span_bug!(pat.span, "unexpected type for tuple pattern: {:?}", sty),
366 PatKind::Binding(bm, def_id, ref ident, ref sub) => {
367 let id = self.tcx.hir.as_local_node_id(def_id).unwrap();
368 let var_ty = self.tables.node_id_to_type(pat.id);
369 let region = match var_ty.sty {
370 ty::TyRef(r, _) => Some(r),
373 let (mutability, mode) = match bm {
374 hir::BindByValue(hir::MutMutable) =>
375 (Mutability::Mut, BindingMode::ByValue),
376 hir::BindByValue(hir::MutImmutable) =>
377 (Mutability::Not, BindingMode::ByValue),
378 hir::BindByRef(hir::MutMutable) =>
379 (Mutability::Not, BindingMode::ByRef(region.unwrap(), BorrowKind::Mut)),
380 hir::BindByRef(hir::MutImmutable) =>
381 (Mutability::Not, BindingMode::ByRef(region.unwrap(), BorrowKind::Shared)),
384 // A ref x pattern is the same node used for x, and as such it has
385 // x's type, which is &T, where we want T (the type being matched).
386 if let hir::BindByRef(_) = bm {
387 if let ty::TyRef(_, mt) = ty.sty {
390 bug!("`ref {}` has wrong type {}", ident.node, ty);
394 PatternKind::Binding {
395 mutability: mutability,
400 subpattern: self.lower_opt_pattern(sub),
404 PatKind::TupleStruct(ref qpath, ref subpatterns, ddpos) => {
405 let def = self.tables.qpath_def(qpath, pat.id);
406 let adt_def = match ty.sty {
407 ty::TyAdt(adt_def, _) => adt_def,
408 _ => span_bug!(pat.span, "tuple struct pattern not applied to an ADT"),
410 let variant_def = adt_def.variant_of_def(def);
414 .enumerate_and_adjust(variant_def.fields.len(), ddpos)
415 .map(|(i, field)| FieldPattern {
416 field: Field::new(i),
417 pattern: self.lower_pattern(field),
420 self.lower_variant_or_leaf(def, ty, subpatterns)
423 PatKind::Struct(ref qpath, ref fields, _) => {
424 let def = self.tables.qpath_def(qpath, pat.id);
425 let adt_def = match ty.sty {
426 ty::TyAdt(adt_def, _) => adt_def,
430 "struct pattern not applied to an ADT");
433 let variant_def = adt_def.variant_of_def(def);
438 let index = variant_def.index_of_field_named(field.node.name);
439 let index = index.unwrap_or_else(|| {
442 "no field with name {:?}",
446 field: Field::new(index),
447 pattern: self.lower_pattern(&field.node.pat),
452 self.lower_variant_or_leaf(def, ty, subpatterns)
459 kind: Box::new(kind),
463 fn lower_patterns(&mut self, pats: &[P<hir::Pat>]) -> Vec<Pattern<'tcx>> {
464 pats.iter().map(|p| self.lower_pattern(p)).collect()
467 fn lower_opt_pattern(&mut self, pat: &Option<P<hir::Pat>>) -> Option<Pattern<'tcx>>
469 pat.as_ref().map(|p| self.lower_pattern(p))
472 fn flatten_nested_slice_patterns(
474 prefix: Vec<Pattern<'tcx>>,
475 slice: Option<Pattern<'tcx>>,
476 suffix: Vec<Pattern<'tcx>>)
477 -> (Vec<Pattern<'tcx>>, Option<Pattern<'tcx>>, Vec<Pattern<'tcx>>)
479 let orig_slice = match slice {
480 Some(orig_slice) => orig_slice,
481 None => return (prefix, slice, suffix)
483 let orig_prefix = prefix;
484 let orig_suffix = suffix;
486 // dance because of intentional borrow-checker stupidity.
487 let kind = *orig_slice.kind;
489 PatternKind::Slice { prefix, slice, mut suffix } |
490 PatternKind::Array { prefix, slice, mut suffix } => {
491 let mut orig_prefix = orig_prefix;
493 orig_prefix.extend(prefix);
494 suffix.extend(orig_suffix);
496 (orig_prefix, slice, suffix)
499 (orig_prefix, Some(Pattern {
500 kind: box kind, ..orig_slice
506 fn slice_or_array_pattern(
510 prefix: &[P<hir::Pat>],
511 slice: &Option<P<hir::Pat>>,
512 suffix: &[P<hir::Pat>])
515 let prefix = self.lower_patterns(prefix);
516 let slice = self.lower_opt_pattern(slice);
517 let suffix = self.lower_patterns(suffix);
518 let (prefix, slice, suffix) =
519 self.flatten_nested_slice_patterns(prefix, slice, suffix);
523 // matching a slice or fixed-length array
524 PatternKind::Slice { prefix: prefix, slice: slice, suffix: suffix }
527 ty::TyArray(_, len) => {
528 // fixed-length array
529 assert!(len >= prefix.len() + suffix.len());
530 PatternKind::Array { prefix: prefix, slice: slice, suffix: suffix }
534 span_bug!(span, "bad slice pattern type {:?}", ty);
539 fn lower_variant_or_leaf(
543 subpatterns: Vec<FieldPattern<'tcx>>)
547 Def::Variant(variant_id) | Def::VariantCtor(variant_id, ..) => {
548 let enum_id = self.tcx.parent_def_id(variant_id).unwrap();
549 let adt_def = self.tcx.adt_def(enum_id);
550 if adt_def.variants.len() > 1 {
551 let substs = match ty.sty {
552 ty::TyAdt(_, substs) |
553 ty::TyFnDef(_, substs) => substs,
554 _ => bug!("inappropriate type for def: {:?}", ty.sty),
556 PatternKind::Variant {
559 variant_index: adt_def.variant_index_with_id(variant_id),
560 subpatterns: subpatterns,
563 PatternKind::Leaf { subpatterns: subpatterns }
567 Def::Struct(..) | Def::StructCtor(..) | Def::Union(..) |
568 Def::TyAlias(..) | Def::AssociatedTy(..) | Def::SelfTy(..) => {
569 PatternKind::Leaf { subpatterns: subpatterns }
576 fn lower_path(&mut self,
582 let ty = self.tables.node_id_to_type(id);
583 let def = self.tables.qpath_def(qpath, id);
584 let kind = match def {
585 Def::Const(def_id) | Def::AssociatedConst(def_id) => {
586 let tcx = self.tcx.global_tcx();
587 let substs = self.tables.node_substs(id);
588 match eval::lookup_const_by_id(tcx, def_id, substs) {
589 Some((def_id, _substs)) => {
590 // Enter the inlined constant's tables temporarily.
591 let old_tables = self.tables;
592 self.tables = tcx.typeck_tables_of(def_id);
593 let body = if let Some(id) = tcx.hir.as_local_node_id(def_id) {
594 tcx.hir.body(tcx.hir.body_owned_by(id))
596 tcx.sess.cstore.item_body(tcx, def_id)
598 let pat = self.lower_const_expr(&body.value, pat_id, span);
599 self.tables = old_tables;
603 self.errors.push(PatternError::StaticInPattern(span));
608 _ => self.lower_variant_or_leaf(def, ty, vec![]),
614 kind: Box::new(kind),
618 fn lower_lit(&mut self, expr: &hir::Expr) -> PatternKind<'tcx> {
619 let const_cx = eval::ConstContext::with_tables(self.tcx.global_tcx(), self.tables);
620 match const_cx.eval(expr) {
622 if let ConstVal::Variant(def_id) = value {
623 let ty = self.tables.expr_ty(expr);
624 self.lower_variant_or_leaf(Def::Variant(def_id), ty, vec![])
626 PatternKind::Constant { value: value }
630 self.errors.push(PatternError::ConstEval(e));
636 fn lower_const_expr(&mut self,
641 let pat_ty = self.tables.expr_ty(expr);
642 debug!("expr={:?} pat_ty={:?} pat_id={}", expr, pat_ty, pat_id);
645 self.tcx.sess.span_err(span, "floating point constants cannot be used in patterns");
647 ty::TyAdt(adt_def, _) if adt_def.is_union() => {
648 // Matching on union fields is unsafe, we can't hide it in constants
649 self.tcx.sess.span_err(span, "cannot use unions in constant patterns");
651 ty::TyAdt(adt_def, _) => {
652 if !self.tcx.has_attr(adt_def.did, "structural_match") {
653 let msg = format!("to use a constant of type `{}` in a pattern, \
654 `{}` must be annotated with `#[derive(PartialEq, Eq)]`",
655 self.tcx.item_path_str(adt_def.did),
656 self.tcx.item_path_str(adt_def.did));
657 self.tcx.sess.span_err(span, &msg);
662 let kind = match expr.node {
663 hir::ExprTup(ref exprs) => {
665 subpatterns: exprs.iter().enumerate().map(|(i, expr)| {
667 field: Field::new(i),
668 pattern: self.lower_const_expr(expr, pat_id, span)
674 hir::ExprCall(ref callee, ref args) => {
675 let qpath = match callee.node {
676 hir::ExprPath(ref qpath) => qpath,
679 let ty = self.tables.node_id_to_type(callee.id);
680 let def = self.tables.qpath_def(qpath, callee.id);
682 Def::Fn(..) | Def::Method(..) => self.lower_lit(expr),
684 let subpatterns = args.iter().enumerate().map(|(i, expr)| {
686 field: Field::new(i),
687 pattern: self.lower_const_expr(expr, pat_id, span)
690 self.lower_variant_or_leaf(def, ty, subpatterns)
695 hir::ExprStruct(ref qpath, ref fields, None) => {
696 let def = self.tables.qpath_def(qpath, expr.id);
697 let adt_def = match pat_ty.sty {
698 ty::TyAdt(adt_def, _) => adt_def,
702 "struct expr without ADT type");
705 let variant_def = adt_def.variant_of_def(def);
710 let index = variant_def.index_of_field_named(field.name.node);
711 let index = index.unwrap_or_else(|| {
714 "no field with name {:?}",
718 field: Field::new(index),
719 pattern: self.lower_const_expr(&field.expr, pat_id, span),
724 self.lower_variant_or_leaf(def, pat_ty, subpatterns)
727 hir::ExprArray(ref exprs) => {
728 let pats = exprs.iter()
729 .map(|expr| self.lower_const_expr(expr, pat_id, span))
738 hir::ExprPath(ref qpath) => {
739 return self.lower_path(qpath, expr.id, pat_id, span);
742 _ => self.lower_lit(expr)
748 kind: Box::new(kind),
753 pub trait PatternFoldable<'tcx> : Sized {
754 fn fold_with<F: PatternFolder<'tcx>>(&self, folder: &mut F) -> Self {
755 self.super_fold_with(folder)
758 fn super_fold_with<F: PatternFolder<'tcx>>(&self, folder: &mut F) -> Self;
761 pub trait PatternFolder<'tcx> : Sized {
762 fn fold_pattern(&mut self, pattern: &Pattern<'tcx>) -> Pattern<'tcx> {
763 pattern.super_fold_with(self)
766 fn fold_pattern_kind(&mut self, kind: &PatternKind<'tcx>) -> PatternKind<'tcx> {
767 kind.super_fold_with(self)
772 impl<'tcx, T: PatternFoldable<'tcx>> PatternFoldable<'tcx> for Box<T> {
773 fn super_fold_with<F: PatternFolder<'tcx>>(&self, folder: &mut F) -> Self {
774 let content: T = (**self).fold_with(folder);
779 impl<'tcx, T: PatternFoldable<'tcx>> PatternFoldable<'tcx> for Vec<T> {
780 fn super_fold_with<F: PatternFolder<'tcx>>(&self, folder: &mut F) -> Self {
781 self.iter().map(|t| t.fold_with(folder)).collect()
785 impl<'tcx, T: PatternFoldable<'tcx>> PatternFoldable<'tcx> for Option<T> {
786 fn super_fold_with<F: PatternFolder<'tcx>>(&self, folder: &mut F) -> Self{
787 self.as_ref().map(|t| t.fold_with(folder))
791 macro_rules! CloneImpls {
792 (<$lt_tcx:tt> $($ty:ty),+) => {
794 impl<$lt_tcx> PatternFoldable<$lt_tcx> for $ty {
795 fn super_fold_with<F: PatternFolder<$lt_tcx>>(&self, _: &mut F) -> Self {
804 Span, Field, Mutability, ast::Name, ast::NodeId, usize, ConstVal<'tcx>, Region<'tcx>,
805 Ty<'tcx>, BindingMode<'tcx>, &'tcx AdtDef,
806 &'tcx Substs<'tcx>, &'tcx Kind<'tcx>
809 impl<'tcx> PatternFoldable<'tcx> for FieldPattern<'tcx> {
810 fn super_fold_with<F: PatternFolder<'tcx>>(&self, folder: &mut F) -> Self {
812 field: self.field.fold_with(folder),
813 pattern: self.pattern.fold_with(folder)
818 impl<'tcx> PatternFoldable<'tcx> for Pattern<'tcx> {
819 fn fold_with<F: PatternFolder<'tcx>>(&self, folder: &mut F) -> Self {
820 folder.fold_pattern(self)
823 fn super_fold_with<F: PatternFolder<'tcx>>(&self, folder: &mut F) -> Self {
825 ty: self.ty.fold_with(folder),
826 span: self.span.fold_with(folder),
827 kind: self.kind.fold_with(folder)
832 impl<'tcx> PatternFoldable<'tcx> for PatternKind<'tcx> {
833 fn fold_with<F: PatternFolder<'tcx>>(&self, folder: &mut F) -> Self {
834 folder.fold_pattern_kind(self)
837 fn super_fold_with<F: PatternFolder<'tcx>>(&self, folder: &mut F) -> Self {
839 PatternKind::Wild => PatternKind::Wild,
840 PatternKind::Binding {
847 } => PatternKind::Binding {
848 mutability: mutability.fold_with(folder),
849 name: name.fold_with(folder),
850 mode: mode.fold_with(folder),
851 var: var.fold_with(folder),
852 ty: ty.fold_with(folder),
853 subpattern: subpattern.fold_with(folder),
855 PatternKind::Variant {
860 } => PatternKind::Variant {
861 adt_def: adt_def.fold_with(folder),
862 substs: substs.fold_with(folder),
863 variant_index: variant_index.fold_with(folder),
864 subpatterns: subpatterns.fold_with(folder)
868 } => PatternKind::Leaf {
869 subpatterns: subpatterns.fold_with(folder),
873 } => PatternKind::Deref {
874 subpattern: subpattern.fold_with(folder),
876 PatternKind::Constant {
878 } => PatternKind::Constant {
879 value: value.fold_with(folder)
885 } => PatternKind::Range {
886 lo: lo.fold_with(folder),
887 hi: hi.fold_with(folder),
894 } => PatternKind::Slice {
895 prefix: prefix.fold_with(folder),
896 slice: slice.fold_with(folder),
897 suffix: suffix.fold_with(folder)
903 } => PatternKind::Array {
904 prefix: prefix.fold_with(folder),
905 slice: slice.fold_with(folder),
906 suffix: suffix.fold_with(folder)