Skip to content

Commit 2c7a19a

Browse files
committed
Adjusted PR to better match project's coding style.
1 parent 70692ce commit 2c7a19a

File tree

1 file changed

+38
-40
lines changed

1 file changed

+38
-40
lines changed

src/librustc/middle/check_match.rs

+38-40
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,8 @@ fn missing_constructors(cx: &MatchCheckCtxt, &Matrix(ref rows): &Matrix,
616616
.collect();
617617
all_constructors(cx, left_ty, max_slice_length)
618618
.into_iter()
619-
.filter(|c| !used_constructors.contains(c)).collect()
619+
.filter(|c| !used_constructors.contains(c))
620+
.collect()
620621
}
621622

622623
/// This determines the set of all possible constructors of a pattern matching
@@ -695,47 +696,44 @@ fn is_useful(cx: &MatchCheckCtxt,
695696

696697
let constructors = pat_constructors(cx, v[0], left_ty, max_slice_length);
697698
if constructors.is_empty() {
698-
match &missing_constructors(cx, matrix, left_ty, max_slice_length)[..] {
699-
[] => {
700-
all_constructors(cx, left_ty, max_slice_length).into_iter().map(|c| {
701-
match is_useful_specialized(cx, matrix, v, c.clone(), left_ty, witness) {
702-
UsefulWithWitness(pats) => UsefulWithWitness({
703-
let arity = constructor_arity(cx, &c, left_ty);
704-
let mut result = {
705-
let pat_slice = &pats[..];
706-
let subpats: Vec<_> = (0..arity).map(|i| {
707-
pat_slice.get(i).map_or(DUMMY_WILD_PAT, |p| &**p)
708-
}).collect();
709-
vec![construct_witness(cx, &c, subpats, left_ty)]
710-
};
711-
result.extend(pats.into_iter().skip(arity));
712-
result
713-
}),
714-
result => result
715-
}
716-
}).find(|result| result != &NotUseful).unwrap_or(NotUseful)
717-
},
718-
719-
[constructors..] => {
720-
let matrix = rows.iter().filter_map(|r| {
721-
if pat_is_binding_or_wild(&cx.tcx.def_map.borrow(), raw_pat(r[0])) {
722-
Some(r[1..].to_vec())
723-
} else {
724-
None
725-
}
726-
}).collect();
727-
match is_useful(cx, &matrix, &v[1..], witness) {
728-
UsefulWithWitness(pats) => {
729-
let mut new_pats: Vec<_> = constructors.into_iter().map(|constructor| {
730-
let arity = constructor_arity(cx, &constructor, left_ty);
731-
let wild_pats = vec![DUMMY_WILD_PAT; arity];
732-
construct_witness(cx, &constructor, wild_pats, left_ty)
733-
}).collect();
734-
new_pats.extend(pats);
735-
UsefulWithWitness(new_pats)
736-
},
699+
let constructors = missing_constructors(cx, matrix, left_ty, max_slice_length);
700+
if constructors.is_empty() {
701+
all_constructors(cx, left_ty, max_slice_length).into_iter().map(|c| {
702+
match is_useful_specialized(cx, matrix, v, c.clone(), left_ty, witness) {
703+
UsefulWithWitness(pats) => UsefulWithWitness({
704+
let arity = constructor_arity(cx, &c, left_ty);
705+
let mut result = {
706+
let pat_slice = &pats[..];
707+
let subpats: Vec<_> = (0..arity).map(|i| {
708+
pat_slice.get(i).map_or(DUMMY_WILD_PAT, |p| &**p)
709+
}).collect();
710+
vec![construct_witness(cx, &c, subpats, left_ty)]
711+
};
712+
result.extend(pats.into_iter().skip(arity));
713+
result
714+
}),
737715
result => result
738716
}
717+
}).find(|result| result != &NotUseful).unwrap_or(NotUseful)
718+
} else {
719+
let matrix = rows.iter().filter_map(|r| {
720+
if pat_is_binding_or_wild(&cx.tcx.def_map.borrow(), raw_pat(r[0])) {
721+
Some(r[1..].to_vec())
722+
} else {
723+
None
724+
}
725+
}).collect();
726+
match is_useful(cx, &matrix, &v[1..], witness) {
727+
UsefulWithWitness(pats) => {
728+
let mut new_pats: Vec<_> = constructors.into_iter().map(|constructor| {
729+
let arity = constructor_arity(cx, &constructor, left_ty);
730+
let wild_pats = vec![DUMMY_WILD_PAT; arity];
731+
construct_witness(cx, &constructor, wild_pats, left_ty)
732+
}).collect();
733+
new_pats.extend(pats);
734+
UsefulWithWitness(new_pats)
735+
},
736+
result => result
739737
}
740738
}
741739
} else {

0 commit comments

Comments
 (0)