Skip to content

Commit 5c9d580

Browse files
committed
Tiny simplification
1 parent f8131a4 commit 5c9d580

File tree

1 file changed

+16
-24
lines changed
  • compiler/rustc_mir_build/src/build/matches

1 file changed

+16
-24
lines changed

compiler/rustc_mir_build/src/build/matches/test.rs

+16-24
Original file line numberDiff line numberDiff line change
@@ -29,44 +29,34 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
2929
///
3030
/// It is a bug to call this with a not-fully-simplified pattern.
3131
pub(super) fn test<'pat>(&mut self, match_pair: &MatchPair<'pat, 'tcx>) -> Test<'tcx> {
32-
match match_pair.pattern.kind {
33-
PatKind::Variant { adt_def, args: _, variant_index: _, subpatterns: _ } => Test {
34-
span: match_pair.pattern.span,
35-
kind: TestKind::Switch {
36-
adt_def,
37-
variants: BitSet::new_empty(adt_def.variants().len()),
38-
},
39-
},
32+
let kind = match match_pair.pattern.kind {
33+
PatKind::Variant { adt_def, args: _, variant_index: _, subpatterns: _ } => {
34+
TestKind::Switch { adt_def, variants: BitSet::new_empty(adt_def.variants().len()) }
35+
}
4036

4137
PatKind::Constant { .. } if is_switch_ty(match_pair.pattern.ty) => {
4238
// For integers, we use a `SwitchInt` match, which allows
4339
// us to handle more cases.
44-
Test {
45-
span: match_pair.pattern.span,
46-
kind: TestKind::SwitchInt {
47-
switch_ty: match_pair.pattern.ty,
48-
49-
// these maps are empty to start; cases are
50-
// added below in add_cases_to_switch
51-
options: Default::default(),
52-
},
40+
TestKind::SwitchInt {
41+
switch_ty: match_pair.pattern.ty,
42+
43+
// these maps are empty to start; cases are
44+
// added below in add_cases_to_switch
45+
options: Default::default(),
5346
}
5447
}
5548

56-
PatKind::Constant { value } => Test {
57-
span: match_pair.pattern.span,
58-
kind: TestKind::Eq { value, ty: match_pair.pattern.ty },
59-
},
49+
PatKind::Constant { value } => TestKind::Eq { value, ty: match_pair.pattern.ty },
6050

6151
PatKind::Range(ref range) => {
6252
assert_eq!(range.ty, match_pair.pattern.ty);
63-
Test { span: match_pair.pattern.span, kind: TestKind::Range(range.clone()) }
53+
TestKind::Range(range.clone())
6454
}
6555

6656
PatKind::Slice { ref prefix, ref slice, ref suffix } => {
6757
let len = prefix.len() + suffix.len();
6858
let op = if slice.is_some() { BinOp::Ge } else { BinOp::Eq };
69-
Test { span: match_pair.pattern.span, kind: TestKind::Len { len: len as u64, op } }
59+
TestKind::Len { len: len as u64, op }
7060
}
7161

7262
PatKind::Or { .. } => bug!("or-patterns should have already been handled"),
@@ -80,7 +70,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
8070
| PatKind::Leaf { .. }
8171
| PatKind::Deref { .. }
8272
| PatKind::Error(_) => self.error_simplifiable(match_pair),
83-
}
73+
};
74+
75+
Test { span: match_pair.pattern.span, kind }
8476
}
8577

8678
pub(super) fn add_cases_to_switch<'pat>(

0 commit comments

Comments
 (0)