1 use crate::build::Builder;
2 use crate::build::matches::MatchPair;
6 use std::convert::TryInto;
8 impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
9 pub fn field_match_pairs<'pat>(&mut self,
11 subpatterns: &'pat [FieldPattern<'tcx>])
12 -> Vec<MatchPair<'pat, 'tcx>> {
15 let place = place.clone().field(fieldpat.field,
17 MatchPair::new(place, &fieldpat.pattern)
22 pub fn prefix_slice_suffix<'pat>(&mut self,
23 match_pairs: &mut Vec<MatchPair<'pat, 'tcx>>,
25 prefix: &'pat [Pattern<'tcx>],
26 opt_slice: Option<&'pat Pattern<'tcx>>,
27 suffix: &'pat [Pattern<'tcx>]) {
28 let min_length = prefix.len() + suffix.len();
29 let min_length = min_length.try_into().unwrap();
34 .map(|(idx, subpattern)| {
35 let elem = ProjectionElem::ConstantIndex {
40 let place = place.clone().elem(elem);
41 MatchPair::new(place, subpattern)
45 if let Some(subslice_pat) = opt_slice {
46 let subslice = place.clone().elem(ProjectionElem::Subslice {
47 from: prefix.len() as u32,
48 to: suffix.len() as u32
50 match_pairs.push(MatchPair::new(subslice, subslice_pat));
57 .map(|(idx, subpattern)| {
58 let elem = ProjectionElem::ConstantIndex {
59 offset: (idx+1) as u32,
63 let place = place.clone().elem(elem);
64 MatchPair::new(place, subpattern)
70 impl<'pat, 'tcx> MatchPair<'pat, 'tcx> {
71 pub fn new(place: Place<'tcx>, pattern: &'pat Pattern<'tcx>) -> MatchPair<'pat, 'tcx> {
75 slice_len_checked: false,