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