Skip to content

Commit d63c324

Browse files
committed
lower_pattern_unadjusted: extract lower_tuple_subpats.
1 parent eb020bc commit d63c324

File tree

1 file changed

+20
-23
lines changed
  • src/librustc_mir/hair/pattern

1 file changed

+20
-23
lines changed

src/librustc_mir/hair/pattern/mod.rs

+20-23
Original file line numberDiff line numberDiff line change
@@ -556,19 +556,12 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
556556
self.slice_or_array_pattern(pat.span, ty, prefix, slice, suffix)
557557
}
558558

559-
hir::PatKind::Tuple(ref subpatterns, ddpos) => {
559+
hir::PatKind::Tuple(ref pats, ddpos) => {
560560
let tys = match ty.kind {
561561
ty::Tuple(ref tys) => tys,
562562
_ => span_bug!(pat.span, "unexpected type for tuple pattern: {:?}", ty),
563563
};
564-
let subpatterns = subpatterns
565-
.iter()
566-
.enumerate_and_adjust(tys.len(), ddpos)
567-
.map(|(i, subpattern)| FieldPat {
568-
field: Field::new(i),
569-
pattern: self.lower_pattern(subpattern)
570-
})
571-
.collect();
564+
let subpatterns = self.lower_tuple_subpats(pats, tys.len(), ddpos);
572565
PatKind::Leaf { subpatterns }
573566
}
574567

@@ -609,25 +602,14 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
609602
}
610603
}
611604

612-
hir::PatKind::TupleStruct(ref qpath, ref subpatterns, ddpos) => {
605+
hir::PatKind::TupleStruct(ref qpath, ref pats, ddpos) => {
613606
let res = self.tables.qpath_res(qpath, pat.hir_id);
614607
let adt_def = match ty.kind {
615608
ty::Adt(adt_def, _) => adt_def,
616-
_ => span_bug!(pat.span,
617-
"tuple struct pattern not applied to an ADT {:?}",
618-
ty),
609+
_ => span_bug!(pat.span, "tuple struct pattern not applied to an ADT {:?}", ty),
619610
};
620611
let variant_def = adt_def.variant_of_res(res);
621-
622-
let subpatterns =
623-
subpatterns.iter()
624-
.enumerate_and_adjust(variant_def.fields.len(), ddpos)
625-
.map(|(i, field)| FieldPat {
626-
field: Field::new(i),
627-
pattern: self.lower_pattern(field),
628-
})
629-
.collect();
630-
612+
let subpatterns = self.lower_tuple_subpats(pats, variant_def.fields.len(), ddpos);
631613
self.lower_variant_or_leaf(res, pat.hir_id, pat.span, ty, subpatterns)
632614
}
633615

@@ -661,6 +643,21 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
661643
}
662644
}
663645

646+
fn lower_tuple_subpats(
647+
&mut self,
648+
pats: &'tcx [P<hir::Pat>],
649+
expected_len: usize,
650+
gap_pos: Option<usize>,
651+
) -> Vec<FieldPat<'tcx>> {
652+
pats.iter()
653+
.enumerate_and_adjust(expected_len, gap_pos)
654+
.map(|(i, subpattern)| FieldPat {
655+
field: Field::new(i),
656+
pattern: self.lower_pattern(subpattern)
657+
})
658+
.collect()
659+
}
660+
664661
fn lower_patterns(&mut self, pats: &'tcx [P<hir::Pat>]) -> Vec<Pat<'tcx>> {
665662
pats.iter().map(|p| self.lower_pattern(p)).collect()
666663
}

0 commit comments

Comments
 (0)