@@ -1059,6 +1059,35 @@ impl fmt::Display for RangeEnd {
1059
1059
}
1060
1060
}
1061
1061
1062
+ // Equivalent to `Option<usize>`. That type takes up 16 bytes on 64-bit, but
1063
+ // this type only takes up 4 bytes, at the cost of being restricted to a
1064
+ // maximum value of `u32::MAX - 1`. In practice, this is more than enough.
1065
+ #[ derive( Clone , Copy , PartialEq , Eq , Hash , HashStable_Generic ) ]
1066
+ pub struct DotDotPos ( u32 ) ;
1067
+
1068
+ impl DotDotPos {
1069
+ // Panics if n >= u32::MAX.
1070
+ pub fn new ( n : Option < usize > ) -> Self {
1071
+ match n {
1072
+ Some ( n) => {
1073
+ assert ! ( n < u32 :: MAX as usize ) ;
1074
+ Self ( n as u32 )
1075
+ }
1076
+ None => Self ( u32:: MAX ) ,
1077
+ }
1078
+ }
1079
+
1080
+ pub fn as_opt_usize ( & self ) -> Option < usize > {
1081
+ if self . 0 == u32:: MAX { None } else { Some ( self . 0 as usize ) }
1082
+ }
1083
+ }
1084
+
1085
+ impl fmt:: Debug for DotDotPos {
1086
+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
1087
+ self . as_opt_usize ( ) . fmt ( f)
1088
+ }
1089
+ }
1090
+
1062
1091
#[ derive( Debug , HashStable_Generic ) ]
1063
1092
pub enum PatKind < ' hir > {
1064
1093
/// Represents a wildcard pattern (i.e., `_`).
@@ -1075,9 +1104,9 @@ pub enum PatKind<'hir> {
1075
1104
Struct ( QPath < ' hir > , & ' hir [ PatField < ' hir > ] , bool ) ,
1076
1105
1077
1106
/// A tuple struct/variant pattern `Variant(x, y, .., z)`.
1078
- /// If the `..` pattern fragment is present, then `Option<usize> ` denotes its position.
1107
+ /// If the `..` pattern fragment is present, then `DotDotPos ` denotes its position.
1079
1108
/// `0 <= position <= subpats.len()`
1080
- TupleStruct ( QPath < ' hir > , & ' hir [ Pat < ' hir > ] , Option < usize > ) ,
1109
+ TupleStruct ( QPath < ' hir > , & ' hir [ Pat < ' hir > ] , DotDotPos ) ,
1081
1110
1082
1111
/// An or-pattern `A | B | C`.
1083
1112
/// Invariant: `pats.len() >= 2`.
@@ -1089,7 +1118,7 @@ pub enum PatKind<'hir> {
1089
1118
/// A tuple pattern (e.g., `(a, b)`).
1090
1119
/// If the `..` pattern fragment is present, then `Option<usize>` denotes its position.
1091
1120
/// `0 <= position <= subpats.len()`
1092
- Tuple ( & ' hir [ Pat < ' hir > ] , Option < usize > ) ,
1121
+ Tuple ( & ' hir [ Pat < ' hir > ] , DotDotPos ) ,
1093
1122
1094
1123
/// A `box` pattern.
1095
1124
Box ( & ' hir Pat < ' hir > ) ,
@@ -3486,8 +3515,8 @@ mod size_asserts {
3486
3515
static_assert_size ! ( ItemKind <' _>, 48 ) ;
3487
3516
static_assert_size ! ( Local <' _>, 64 ) ;
3488
3517
static_assert_size ! ( Param <' _>, 32 ) ;
3489
- static_assert_size ! ( Pat <' _>, 88 ) ;
3490
- static_assert_size ! ( PatKind <' _>, 64 ) ;
3518
+ static_assert_size ! ( Pat <' _>, 72 ) ;
3519
+ static_assert_size ! ( PatKind <' _>, 48 ) ;
3491
3520
static_assert_size ! ( Path <' _>, 48 ) ;
3492
3521
static_assert_size ! ( PathSegment <' _>, 56 ) ;
3493
3522
static_assert_size ! ( QPath <' _>, 24 ) ;
0 commit comments