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.
14 use rustc::middle::const_val::{ConstEvalErr, ConstVal};
15 use rustc::mir::{Field, BorrowKind, Mutability};
16 use rustc::ty::{self, TyCtxt, AdtDef, Ty, TypeVariants, Region};
17 use rustc::ty::subst::{Substs, Kind};
18 use rustc::hir::{self, PatKind, RangeEnd};
19 use rustc::hir::def::{Def, CtorKind};
20 use rustc::hir::pat_util::EnumerateAndAdjustIterator;
22 use rustc_data_structures::indexed_vec::Idx;
29 #[derive(Clone, Debug)]
30 pub enum PatternError<'tcx> {
31 StaticInPattern(Span),
32 ConstEval(ConstEvalErr<'tcx>),
35 #[derive(Copy, Clone, Debug)]
36 pub enum BindingMode<'tcx> {
38 ByRef(&'tcx Region, BorrowKind),
41 #[derive(Clone, Debug)]
42 pub struct FieldPattern<'tcx> {
44 pub pattern: Pattern<'tcx>,
47 #[derive(Clone, Debug)]
48 pub struct Pattern<'tcx> {
51 pub kind: Box<PatternKind<'tcx>>,
54 #[derive(Clone, Debug)]
55 pub enum PatternKind<'tcx> {
58 /// x, ref x, x @ P, etc
60 mutability: Mutability,
62 mode: BindingMode<'tcx>,
65 subpattern: Option<Pattern<'tcx>>,
68 /// Foo(...) or Foo{...} or Foo, where `Foo` is a variant name from an adt with >1 variants
70 adt_def: &'tcx AdtDef,
71 substs: &'tcx Substs<'tcx>,
73 subpatterns: Vec<FieldPattern<'tcx>>,
76 /// (...), Foo(...), Foo{...}, or Foo, where `Foo` is a variant name from an adt with 1 variant
78 subpatterns: Vec<FieldPattern<'tcx>>,
81 /// box P, &P, &mut P, etc
83 subpattern: Pattern<'tcx>,
87 value: ConstVal<'tcx>,
96 /// matches against a slice, checking the length and extracting elements
98 prefix: Vec<Pattern<'tcx>>,
99 slice: Option<Pattern<'tcx>>,
100 suffix: Vec<Pattern<'tcx>>,
103 /// fixed match against an array, irrefutable
105 prefix: Vec<Pattern<'tcx>>,
106 slice: Option<Pattern<'tcx>>,
107 suffix: Vec<Pattern<'tcx>>,
111 fn print_const_val(value: &ConstVal, f: &mut fmt::Formatter) -> fmt::Result {
113 ConstVal::Float(ref x) => write!(f, "{}", x),
114 ConstVal::Integral(ref i) => write!(f, "{}", i),
115 ConstVal::Str(ref s) => write!(f, "{:?}", &s[..]),
116 ConstVal::ByteStr(ref b) => write!(f, "{:?}", &b[..]),
117 ConstVal::Bool(b) => write!(f, "{:?}", b),
118 ConstVal::Char(c) => write!(f, "{:?}", c),
119 ConstVal::Variant(_) |
120 ConstVal::Struct(_) |
122 ConstVal::Function(..) |
123 ConstVal::Array(..) |
124 ConstVal::Repeat(..) => bug!("{:?} not printable in a pattern", value)
128 impl<'tcx> fmt::Display for Pattern<'tcx> {
129 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
131 PatternKind::Wild => write!(f, "_"),
132 PatternKind::Binding { mutability, name, mode, ref subpattern, .. } => {
133 let is_mut = match mode {
134 BindingMode::ByValue => mutability == Mutability::Mut,
135 BindingMode::ByRef(_, bk) => {
137 bk == BorrowKind::Mut
143 write!(f, "{}", name)?;
144 if let Some(ref subpattern) = *subpattern {
145 write!(f, " @ {}", subpattern)?;
149 PatternKind::Variant { ref subpatterns, .. } |
150 PatternKind::Leaf { ref subpatterns } => {
151 let variant = match *self.kind {
152 PatternKind::Variant { adt_def, variant_index, .. } => {
153 Some(&adt_def.variants[variant_index])
155 _ => if let ty::TyAdt(adt, _) = self.ty.sty {
156 if adt.is_univariant() {
157 Some(&adt.variants[0])
166 let mut first = true;
167 let mut start_or_continue = || if first { first = false; "" } else { ", " };
169 if let Some(variant) = variant {
170 write!(f, "{}", variant.name)?;
172 // Only for TyAdt we can have `S {...}`,
173 // which we handle separately here.
174 if variant.ctor_kind == CtorKind::Fictive {
178 for p in subpatterns {
179 if let PatternKind::Wild = *p.pattern.kind {
182 let name = variant.fields[p.field.index()].name;
183 write!(f, "{}{}: {}", start_or_continue(), name, p.pattern)?;
187 if printed < variant.fields.len() {
188 write!(f, "{}..", start_or_continue())?;
191 return write!(f, " }}");
195 let num_fields = variant.map_or(subpatterns.len(), |v| v.fields.len());
196 if num_fields != 0 || variant.is_none() {
198 for i in 0..num_fields {
199 write!(f, "{}", start_or_continue())?;
201 // Common case: the field is where we expect it.
202 if let Some(p) = subpatterns.get(i) {
203 if p.field.index() == i {
204 write!(f, "{}", p.pattern)?;
209 // Otherwise, we have to go looking for it.
210 if let Some(p) = subpatterns.iter().find(|p| p.field.index() == i) {
211 write!(f, "{}", p.pattern)?;
221 PatternKind::Deref { ref subpattern } => {
223 ty::TyAdt(def, _) if def.is_box() => write!(f, "box ")?,
224 ty::TyRef(_, mt) => {
226 if mt.mutbl == hir::MutMutable {
230 _ => bug!("{} is a bad Deref pattern type", self.ty)
232 write!(f, "{}", subpattern)
234 PatternKind::Constant { ref value } => {
235 print_const_val(value, f)
237 PatternKind::Range { ref lo, ref hi, ref end } => {
238 print_const_val(lo, f)?;
240 RangeEnd::Included => write!(f, "...")?,
241 RangeEnd::Excluded => write!(f, "..")?,
243 print_const_val(hi, f)
245 PatternKind::Slice { ref prefix, ref slice, ref suffix } |
246 PatternKind::Array { ref prefix, ref slice, ref suffix } => {
247 let mut first = true;
248 let mut start_or_continue = || if first { first = false; "" } else { ", " };
251 write!(f, "{}{}", start_or_continue(), p)?;
253 if let Some(ref slice) = *slice {
254 write!(f, "{}", start_or_continue())?;
256 PatternKind::Wild => {}
257 _ => write!(f, "{}", slice)?
262 write!(f, "{}{}", start_or_continue(), p)?;
270 pub struct PatternContext<'a, 'gcx: 'tcx, 'tcx: 'a> {
271 pub tcx: TyCtxt<'a, 'gcx, 'tcx>,
272 pub tables: &'a ty::TypeckTables<'gcx>,
273 pub errors: Vec<PatternError<'tcx>>,
276 impl<'a, 'gcx, 'tcx> Pattern<'tcx> {
277 pub fn from_hir(tcx: TyCtxt<'a, 'gcx, 'tcx>,
278 tables: &'a ty::TypeckTables<'gcx>,
279 pat: &hir::Pat) -> Self {
280 let mut pcx = PatternContext::new(tcx, tables);
281 let result = pcx.lower_pattern(pat);
282 if !pcx.errors.is_empty() {
283 span_bug!(pat.span, "encountered errors lowering pattern: {:?}", pcx.errors)
285 debug!("Pattern::from_hir({:?}) = {:?}", pat, result);
290 impl<'a, 'gcx, 'tcx> PatternContext<'a, 'gcx, 'tcx> {
291 pub fn new(tcx: TyCtxt<'a, 'gcx, 'tcx>, tables: &'a ty::TypeckTables<'gcx>) -> Self {
292 PatternContext { tcx: tcx, tables: tables, errors: vec![] }
295 pub fn lower_pattern(&mut self, pat: &hir::Pat) -> Pattern<'tcx> {
296 let mut ty = self.tables.node_id_to_type(pat.id);
298 let kind = match pat.node {
299 PatKind::Wild => PatternKind::Wild,
301 PatKind::Lit(ref value) => self.lower_lit(value),
303 PatKind::Range(ref lo, ref hi, ref end) => {
304 match (self.lower_lit(lo), self.lower_lit(hi)) {
305 (PatternKind::Constant { value: lo },
306 PatternKind::Constant { value: hi }) => {
307 PatternKind::Range { lo: lo, hi: hi, end: end.clone() }
309 _ => PatternKind::Wild
313 PatKind::Path(ref qpath) => {
314 return self.lower_path(qpath, pat.id, pat.id, pat.span);
317 PatKind::Ref(ref subpattern, _) |
318 PatKind::Box(ref subpattern) => {
319 PatternKind::Deref { subpattern: self.lower_pattern(subpattern) }
322 PatKind::Slice(ref prefix, ref slice, ref suffix) => {
323 let ty = self.tables.node_id_to_type(pat.id);
327 subpattern: Pattern {
330 kind: Box::new(self.slice_or_array_pattern(
331 pat.span, mt.ty, prefix, slice, suffix))
337 self.slice_or_array_pattern(pat.span, ty, prefix, slice, suffix),
342 "unexpanded type for vector pattern: {:?}",
347 PatKind::Tuple(ref subpatterns, ddpos) => {
348 let ty = self.tables.node_id_to_type(pat.id);
350 ty::TyTuple(ref tys, _) => {
353 .enumerate_and_adjust(tys.len(), ddpos)
354 .map(|(i, subpattern)| FieldPattern {
355 field: Field::new(i),
356 pattern: self.lower_pattern(subpattern)
360 PatternKind::Leaf { subpatterns: subpatterns }
363 ref sty => span_bug!(pat.span, "unexpected type for tuple pattern: {:?}", sty),
367 PatKind::Binding(bm, def_id, ref ident, ref sub) => {
368 let id = self.tcx.hir.as_local_node_id(def_id).unwrap();
369 let var_ty = self.tables.node_id_to_type(pat.id);
370 let region = match var_ty.sty {
371 ty::TyRef(r, _) => Some(r),
374 let (mutability, mode) = match bm {
375 hir::BindByValue(hir::MutMutable) =>
376 (Mutability::Mut, BindingMode::ByValue),
377 hir::BindByValue(hir::MutImmutable) =>
378 (Mutability::Not, BindingMode::ByValue),
379 hir::BindByRef(hir::MutMutable) =>
380 (Mutability::Not, BindingMode::ByRef(region.unwrap(), BorrowKind::Mut)),
381 hir::BindByRef(hir::MutImmutable) =>
382 (Mutability::Not, BindingMode::ByRef(region.unwrap(), BorrowKind::Shared)),
385 // A ref x pattern is the same node used for x, and as such it has
386 // x's type, which is &T, where we want T (the type being matched).
387 if let hir::BindByRef(_) = bm {
388 if let ty::TyRef(_, mt) = ty.sty {
391 bug!("`ref {}` has wrong type {}", ident.node, ty);
395 PatternKind::Binding {
396 mutability: mutability,
401 subpattern: self.lower_opt_pattern(sub),
405 PatKind::TupleStruct(ref qpath, ref subpatterns, ddpos) => {
406 let def = self.tables.qpath_def(qpath, pat.id);
407 let adt_def = match ty.sty {
408 ty::TyAdt(adt_def, _) => adt_def,
409 _ => span_bug!(pat.span, "tuple struct pattern not applied to an ADT"),
411 let variant_def = adt_def.variant_of_def(def);
415 .enumerate_and_adjust(variant_def.fields.len(), ddpos)
416 .map(|(i, field)| FieldPattern {
417 field: Field::new(i),
418 pattern: self.lower_pattern(field),
421 self.lower_variant_or_leaf(def, ty, subpatterns)
424 PatKind::Struct(ref qpath, ref fields, _) => {
425 let def = self.tables.qpath_def(qpath, pat.id);
426 let adt_def = match ty.sty {
427 ty::TyAdt(adt_def, _) => adt_def,
431 "struct pattern not applied to an ADT");
434 let variant_def = adt_def.variant_of_def(def);
439 let index = variant_def.index_of_field_named(field.node.name);
440 let index = index.unwrap_or_else(|| {
443 "no field with name {:?}",
447 field: Field::new(index),
448 pattern: self.lower_pattern(&field.node.pat),
453 self.lower_variant_or_leaf(def, ty, subpatterns)
460 kind: Box::new(kind),
464 fn lower_patterns(&mut self, pats: &[P<hir::Pat>]) -> Vec<Pattern<'tcx>> {
465 pats.iter().map(|p| self.lower_pattern(p)).collect()
468 fn lower_opt_pattern(&mut self, pat: &Option<P<hir::Pat>>) -> Option<Pattern<'tcx>>
470 pat.as_ref().map(|p| self.lower_pattern(p))
473 fn flatten_nested_slice_patterns(
475 prefix: Vec<Pattern<'tcx>>,
476 slice: Option<Pattern<'tcx>>,
477 suffix: Vec<Pattern<'tcx>>)
478 -> (Vec<Pattern<'tcx>>, Option<Pattern<'tcx>>, Vec<Pattern<'tcx>>)
480 let orig_slice = match slice {
481 Some(orig_slice) => orig_slice,
482 None => return (prefix, slice, suffix)
484 let orig_prefix = prefix;
485 let orig_suffix = suffix;
487 // dance because of intentional borrow-checker stupidity.
488 let kind = *orig_slice.kind;
490 PatternKind::Slice { prefix, slice, mut suffix } |
491 PatternKind::Array { prefix, slice, mut suffix } => {
492 let mut orig_prefix = orig_prefix;
494 orig_prefix.extend(prefix);
495 suffix.extend(orig_suffix);
497 (orig_prefix, slice, suffix)
500 (orig_prefix, Some(Pattern {
501 kind: box kind, ..orig_slice
507 fn slice_or_array_pattern(
511 prefix: &[P<hir::Pat>],
512 slice: &Option<P<hir::Pat>>,
513 suffix: &[P<hir::Pat>])
516 let prefix = self.lower_patterns(prefix);
517 let slice = self.lower_opt_pattern(slice);
518 let suffix = self.lower_patterns(suffix);
519 let (prefix, slice, suffix) =
520 self.flatten_nested_slice_patterns(prefix, slice, suffix);
524 // matching a slice or fixed-length array
525 PatternKind::Slice { prefix: prefix, slice: slice, suffix: suffix }
528 ty::TyArray(_, len) => {
529 // fixed-length array
530 assert!(len >= prefix.len() + suffix.len());
531 PatternKind::Array { prefix: prefix, slice: slice, suffix: suffix }
535 span_bug!(span, "bad slice pattern type {:?}", ty);
540 fn lower_variant_or_leaf(
544 subpatterns: Vec<FieldPattern<'tcx>>)
548 Def::Variant(variant_id) | Def::VariantCtor(variant_id, ..) => {
549 let enum_id = self.tcx.parent_def_id(variant_id).unwrap();
550 let adt_def = self.tcx.adt_def(enum_id);
551 if adt_def.variants.len() > 1 {
552 let substs = match ty.sty {
553 TypeVariants::TyAdt(_, substs) => substs,
554 TypeVariants::TyFnDef(_, substs, _) => substs,
555 _ => bug!("inappropriate type for def: {:?}", ty.sty),
557 PatternKind::Variant {
560 variant_index: adt_def.variant_index_with_id(variant_id),
561 subpatterns: subpatterns,
564 PatternKind::Leaf { subpatterns: subpatterns }
568 Def::Struct(..) | Def::StructCtor(..) | Def::Union(..) |
569 Def::TyAlias(..) | Def::AssociatedTy(..) | Def::SelfTy(..) => {
570 PatternKind::Leaf { subpatterns: subpatterns }
577 fn lower_path(&mut self,
583 let ty = self.tables.node_id_to_type(id);
584 let def = self.tables.qpath_def(qpath, id);
585 let kind = match def {
586 Def::Const(def_id) | Def::AssociatedConst(def_id) => {
587 let tcx = self.tcx.global_tcx();
588 let substs = self.tables.node_id_item_substs(id)
589 .unwrap_or_else(|| tcx.intern_substs(&[]));
590 match eval::lookup_const_by_id(tcx, def_id, substs) {
591 Some((def_id, _substs)) => {
592 // Enter the inlined constant's tables temporarily.
593 let old_tables = self.tables;
594 self.tables = tcx.typeck_tables_of(def_id);
595 let body = if let Some(id) = tcx.hir.as_local_node_id(def_id) {
596 tcx.hir.body(tcx.hir.body_owned_by(id))
598 tcx.sess.cstore.item_body(tcx, def_id)
600 let pat = self.lower_const_expr(&body.value, pat_id, span);
601 self.tables = old_tables;
605 self.errors.push(PatternError::StaticInPattern(span));
610 _ => self.lower_variant_or_leaf(def, ty, vec![]),
616 kind: Box::new(kind),
620 fn lower_lit(&mut self, expr: &hir::Expr) -> PatternKind<'tcx> {
621 let const_cx = eval::ConstContext::with_tables(self.tcx.global_tcx(), self.tables);
622 match const_cx.eval(expr) {
624 if let ConstVal::Variant(def_id) = value {
625 let ty = self.tables.expr_ty(expr);
626 self.lower_variant_or_leaf(Def::Variant(def_id), ty, vec![])
628 PatternKind::Constant { value: value }
632 self.errors.push(PatternError::ConstEval(e));
638 fn lower_const_expr(&mut self,
643 let pat_ty = self.tables.expr_ty(expr);
644 debug!("expr={:?} pat_ty={:?} pat_id={}", expr, pat_ty, pat_id);
647 self.tcx.sess.add_lint(
648 lint::builtin::ILLEGAL_FLOATING_POINT_CONSTANT_PATTERN,
651 format!("floating point constants cannot be used in patterns"));
653 ty::TyAdt(adt_def, _) if adt_def.is_union() => {
654 // Matching on union fields is unsafe, we can't hide it in constants
655 self.tcx.sess.span_err(span, "cannot use unions in constant patterns");
657 ty::TyAdt(adt_def, _) => {
658 if !self.tcx.has_attr(adt_def.did, "structural_match") {
659 self.tcx.sess.add_lint(
660 lint::builtin::ILLEGAL_STRUCT_OR_ENUM_CONSTANT_PATTERN,
663 format!("to use a constant of type `{}` \
665 `{}` must be annotated with `#[derive(PartialEq, Eq)]`",
666 self.tcx.item_path_str(adt_def.did),
667 self.tcx.item_path_str(adt_def.did)));
672 let kind = match expr.node {
673 hir::ExprTup(ref exprs) => {
675 subpatterns: exprs.iter().enumerate().map(|(i, expr)| {
677 field: Field::new(i),
678 pattern: self.lower_const_expr(expr, pat_id, span)
684 hir::ExprCall(ref callee, ref args) => {
685 let qpath = match callee.node {
686 hir::ExprPath(ref qpath) => qpath,
689 let ty = self.tables.node_id_to_type(callee.id);
690 let def = self.tables.qpath_def(qpath, callee.id);
692 Def::Fn(..) | Def::Method(..) => self.lower_lit(expr),
694 let subpatterns = args.iter().enumerate().map(|(i, expr)| {
696 field: Field::new(i),
697 pattern: self.lower_const_expr(expr, pat_id, span)
700 self.lower_variant_or_leaf(def, ty, subpatterns)
705 hir::ExprStruct(ref qpath, ref fields, None) => {
706 let def = self.tables.qpath_def(qpath, expr.id);
707 let adt_def = match pat_ty.sty {
708 ty::TyAdt(adt_def, _) => adt_def,
712 "struct expr without ADT type");
715 let variant_def = adt_def.variant_of_def(def);
720 let index = variant_def.index_of_field_named(field.name.node);
721 let index = index.unwrap_or_else(|| {
724 "no field with name {:?}",
728 field: Field::new(index),
729 pattern: self.lower_const_expr(&field.expr, pat_id, span),
734 self.lower_variant_or_leaf(def, pat_ty, subpatterns)
737 hir::ExprArray(ref exprs) => {
738 let pats = exprs.iter()
739 .map(|expr| self.lower_const_expr(expr, pat_id, span))
748 hir::ExprPath(ref qpath) => {
749 return self.lower_path(qpath, expr.id, pat_id, span);
752 _ => self.lower_lit(expr)
758 kind: Box::new(kind),
763 pub trait PatternFoldable<'tcx> : Sized {
764 fn fold_with<F: PatternFolder<'tcx>>(&self, folder: &mut F) -> Self {
765 self.super_fold_with(folder)
768 fn super_fold_with<F: PatternFolder<'tcx>>(&self, folder: &mut F) -> Self;
771 pub trait PatternFolder<'tcx> : Sized {
772 fn fold_pattern(&mut self, pattern: &Pattern<'tcx>) -> Pattern<'tcx> {
773 pattern.super_fold_with(self)
776 fn fold_pattern_kind(&mut self, kind: &PatternKind<'tcx>) -> PatternKind<'tcx> {
777 kind.super_fold_with(self)
782 impl<'tcx, T: PatternFoldable<'tcx>> PatternFoldable<'tcx> for Box<T> {
783 fn super_fold_with<F: PatternFolder<'tcx>>(&self, folder: &mut F) -> Self {
784 let content: T = (**self).fold_with(folder);
789 impl<'tcx, T: PatternFoldable<'tcx>> PatternFoldable<'tcx> for Vec<T> {
790 fn super_fold_with<F: PatternFolder<'tcx>>(&self, folder: &mut F) -> Self {
791 self.iter().map(|t| t.fold_with(folder)).collect()
795 impl<'tcx, T: PatternFoldable<'tcx>> PatternFoldable<'tcx> for Option<T> {
796 fn super_fold_with<F: PatternFolder<'tcx>>(&self, folder: &mut F) -> Self{
797 self.as_ref().map(|t| t.fold_with(folder))
801 macro_rules! CloneImpls {
802 (<$lt_tcx:tt> $($ty:ty),+) => {
804 impl<$lt_tcx> PatternFoldable<$lt_tcx> for $ty {
805 fn super_fold_with<F: PatternFolder<$lt_tcx>>(&self, _: &mut F) -> Self {
814 Span, Field, Mutability, ast::Name, ast::NodeId, usize, ConstVal<'tcx>, Region,
815 Ty<'tcx>, BindingMode<'tcx>, &'tcx AdtDef,
816 &'tcx Substs<'tcx>, &'tcx Kind<'tcx>
819 impl<'tcx> PatternFoldable<'tcx> for FieldPattern<'tcx> {
820 fn super_fold_with<F: PatternFolder<'tcx>>(&self, folder: &mut F) -> Self {
822 field: self.field.fold_with(folder),
823 pattern: self.pattern.fold_with(folder)
828 impl<'tcx> PatternFoldable<'tcx> for Pattern<'tcx> {
829 fn fold_with<F: PatternFolder<'tcx>>(&self, folder: &mut F) -> Self {
830 folder.fold_pattern(self)
833 fn super_fold_with<F: PatternFolder<'tcx>>(&self, folder: &mut F) -> Self {
835 ty: self.ty.fold_with(folder),
836 span: self.span.fold_with(folder),
837 kind: self.kind.fold_with(folder)
842 impl<'tcx> PatternFoldable<'tcx> for PatternKind<'tcx> {
843 fn fold_with<F: PatternFolder<'tcx>>(&self, folder: &mut F) -> Self {
844 folder.fold_pattern_kind(self)
847 fn super_fold_with<F: PatternFolder<'tcx>>(&self, folder: &mut F) -> Self {
849 PatternKind::Wild => PatternKind::Wild,
850 PatternKind::Binding {
857 } => PatternKind::Binding {
858 mutability: mutability.fold_with(folder),
859 name: name.fold_with(folder),
860 mode: mode.fold_with(folder),
861 var: var.fold_with(folder),
862 ty: ty.fold_with(folder),
863 subpattern: subpattern.fold_with(folder),
865 PatternKind::Variant {
870 } => PatternKind::Variant {
871 adt_def: adt_def.fold_with(folder),
872 substs: substs.fold_with(folder),
873 variant_index: variant_index.fold_with(folder),
874 subpatterns: subpatterns.fold_with(folder)
878 } => PatternKind::Leaf {
879 subpatterns: subpatterns.fold_with(folder),
883 } => PatternKind::Deref {
884 subpattern: subpattern.fold_with(folder),
886 PatternKind::Constant {
888 } => PatternKind::Constant {
889 value: value.fold_with(folder)
895 } => PatternKind::Range {
896 lo: lo.fold_with(folder),
897 hi: hi.fold_with(folder),
904 } => PatternKind::Slice {
905 prefix: prefix.fold_with(folder),
906 slice: slice.fold_with(folder),
907 suffix: suffix.fold_with(folder)
913 } => PatternKind::Array {
914 prefix: prefix.fold_with(folder),
915 slice: slice.fold_with(folder),
916 suffix: suffix.fold_with(folder)