@@ -55,6 +55,17 @@ fn is_short_pattern_inner(pat: &ast::Pat) -> bool {
55
55
}
56
56
}
57
57
58
+ struct RangeOperand < ' a > ( & ' a Option < ptr:: P < ast:: Expr > > ) ;
59
+
60
+ impl < ' a > Rewrite for RangeOperand < ' a > {
61
+ fn rewrite ( & self , context : & RewriteContext < ' _ > , shape : Shape ) -> Option < String > {
62
+ match & self . 0 {
63
+ None => Some ( "" . to_owned ( ) ) ,
64
+ Some ( ref exp) => exp. rewrite ( context, shape) ,
65
+ }
66
+ }
67
+ }
68
+
58
69
impl Rewrite for Pat {
59
70
fn rewrite ( & self , context : & RewriteContext < ' _ > , shape : Shape ) -> Option < String > {
60
71
match self . kind {
@@ -179,29 +190,34 @@ impl Rewrite for Pat {
179
190
None
180
191
}
181
192
}
182
- PatKind :: Range ( ref lhs, ref rhs, ref end_kind) => match ( lhs, rhs) {
183
- ( Some ( lhs) , Some ( rhs) ) => {
184
- let infix = match end_kind. node {
185
- RangeEnd :: Included ( RangeSyntax :: DotDotDot ) => "..." ,
186
- RangeEnd :: Included ( RangeSyntax :: DotDotEq ) => "..=" ,
187
- RangeEnd :: Excluded => ".." ,
193
+ PatKind :: Range ( ref lhs, ref rhs, ref end_kind) => {
194
+ let infix = match end_kind. node {
195
+ RangeEnd :: Included ( RangeSyntax :: DotDotDot ) => "..." ,
196
+ RangeEnd :: Included ( RangeSyntax :: DotDotEq ) => "..=" ,
197
+ RangeEnd :: Excluded => ".." ,
198
+ } ;
199
+ let infix = if context. config . spaces_around_ranges ( ) {
200
+ let lhs_spacing = match lhs {
201
+ None => "" ,
202
+ Some ( _) => " " ,
188
203
} ;
189
- let infix = if context. config . spaces_around_ranges ( ) {
190
- format ! ( " {} " , infix)
191
- } else {
192
- infix. to_owned ( )
204
+ let rhs_spacing = match rhs {
205
+ None => "" ,
206
+ Some ( _) => " " ,
193
207
} ;
194
- rewrite_pair (
195
- & * * lhs,
196
- & * * rhs,
197
- PairParts :: infix ( & infix) ,
198
- context,
199
- shape,
200
- SeparatorPlace :: Front ,
201
- )
202
- }
203
- ( _, _) => unimplemented ! ( ) ,
204
- } ,
208
+ format ! ( "{}{}{}" , lhs_spacing, infix, rhs_spacing)
209
+ } else {
210
+ infix. to_owned ( )
211
+ } ;
212
+ rewrite_pair (
213
+ & RangeOperand ( lhs) ,
214
+ & RangeOperand ( rhs) ,
215
+ PairParts :: infix ( & infix) ,
216
+ context,
217
+ shape,
218
+ SeparatorPlace :: Front ,
219
+ )
220
+ }
205
221
PatKind :: Ref ( ref pat, mutability) => {
206
222
let prefix = format ! ( "&{}" , format_mutability( mutability) ) ;
207
223
rewrite_unary_prefix ( context, & prefix, & * * pat, shape)
0 commit comments