@@ -29,44 +29,34 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
29
29
///
30
30
/// It is a bug to call this with a not-fully-simplified pattern.
31
31
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
+ }
40
36
41
37
PatKind :: Constant { .. } if is_switch_ty ( match_pair. pattern . ty ) => {
42
38
// For integers, we use a `SwitchInt` match, which allows
43
39
// 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 ( ) ,
53
46
}
54
47
}
55
48
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 } ,
60
50
61
51
PatKind :: Range ( ref range) => {
62
52
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 ( ) )
64
54
}
65
55
66
56
PatKind :: Slice { ref prefix, ref slice, ref suffix } => {
67
57
let len = prefix. len ( ) + suffix. len ( ) ;
68
58
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 }
70
60
}
71
61
72
62
PatKind :: Or { .. } => bug ! ( "or-patterns should have already been handled" ) ,
@@ -80,7 +70,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
80
70
| PatKind :: Leaf { .. }
81
71
| PatKind :: Deref { .. }
82
72
| PatKind :: Error ( _) => self . error_simplifiable ( match_pair) ,
83
- }
73
+ } ;
74
+
75
+ Test { span : match_pair. pattern . span , kind }
84
76
}
85
77
86
78
pub ( super ) fn add_cases_to_switch < ' pat > (
0 commit comments