@@ -75,12 +75,12 @@ fn is_short_pattern_inner(context: &RewriteContext<'_>, pat: &ast::Pat) -> bool
75
75
}
76
76
}
77
77
78
- pub ( crate ) struct RangeOperand < ' a > {
79
- operand : & ' a Option < ptr:: P < ast :: Expr > > ,
80
- pub ( crate ) span : Span ,
78
+ pub ( crate ) struct RangeOperand < ' a , T > {
79
+ pub operand : & ' a Option < ptr:: P < T > > ,
80
+ pub span : Span ,
81
81
}
82
82
83
- impl < ' a > Rewrite for RangeOperand < ' a > {
83
+ impl < ' a , T : Rewrite > Rewrite for RangeOperand < ' a , T > {
84
84
fn rewrite ( & self , context : & RewriteContext < ' _ > , shape : Shape ) -> Option < String > {
85
85
self . rewrite_result ( context, shape) . ok ( )
86
86
}
@@ -259,40 +259,7 @@ impl Rewrite for Pat {
259
259
}
260
260
PatKind :: Never => Err ( RewriteError :: Unknown ) ,
261
261
PatKind :: Range ( ref lhs, ref rhs, ref end_kind) => {
262
- let infix = match end_kind. node {
263
- RangeEnd :: Included ( RangeSyntax :: DotDotDot ) => "..." ,
264
- RangeEnd :: Included ( RangeSyntax :: DotDotEq ) => "..=" ,
265
- RangeEnd :: Excluded => ".." ,
266
- } ;
267
- let infix = if context. config . spaces_around_ranges ( ) {
268
- let lhs_spacing = match lhs {
269
- None => "" ,
270
- Some ( _) => " " ,
271
- } ;
272
- let rhs_spacing = match rhs {
273
- None => "" ,
274
- Some ( _) => " " ,
275
- } ;
276
- format ! ( "{lhs_spacing}{infix}{rhs_spacing}" )
277
- } else {
278
- infix. to_owned ( )
279
- } ;
280
- let lspan = self . span . with_hi ( end_kind. span . lo ( ) ) ;
281
- let rspan = self . span . with_lo ( end_kind. span . hi ( ) ) ;
282
- rewrite_pair (
283
- & RangeOperand {
284
- operand : lhs,
285
- span : lspan,
286
- } ,
287
- & RangeOperand {
288
- operand : rhs,
289
- span : rspan,
290
- } ,
291
- PairParts :: infix ( & infix) ,
292
- context,
293
- shape,
294
- SeparatorPlace :: Front ,
295
- )
262
+ rewrite_range_pat ( context, shape, lhs, rhs, end_kind, self . span )
296
263
}
297
264
PatKind :: Ref ( ref pat, mutability) => {
298
265
let prefix = format ! ( "&{}" , format_mutability( mutability) ) ;
@@ -359,6 +326,50 @@ impl Rewrite for Pat {
359
326
}
360
327
}
361
328
329
+ pub fn rewrite_range_pat < T : Rewrite > (
330
+ context : & RewriteContext < ' _ > ,
331
+ shape : Shape ,
332
+ lhs : & Option < ptr:: P < T > > ,
333
+ rhs : & Option < ptr:: P < T > > ,
334
+ end_kind : & rustc_span:: source_map:: Spanned < RangeEnd > ,
335
+ span : Span ,
336
+ ) -> RewriteResult {
337
+ let infix = match end_kind. node {
338
+ RangeEnd :: Included ( RangeSyntax :: DotDotDot ) => "..." ,
339
+ RangeEnd :: Included ( RangeSyntax :: DotDotEq ) => "..=" ,
340
+ RangeEnd :: Excluded => ".." ,
341
+ } ;
342
+ let infix = if context. config . spaces_around_ranges ( ) {
343
+ let lhs_spacing = match lhs {
344
+ None => "" ,
345
+ Some ( _) => " " ,
346
+ } ;
347
+ let rhs_spacing = match rhs {
348
+ None => "" ,
349
+ Some ( _) => " " ,
350
+ } ;
351
+ format ! ( "{lhs_spacing}{infix}{rhs_spacing}" )
352
+ } else {
353
+ infix. to_owned ( )
354
+ } ;
355
+ let lspan = span. with_hi ( end_kind. span . lo ( ) ) ;
356
+ let rspan = span. with_lo ( end_kind. span . hi ( ) ) ;
357
+ rewrite_pair (
358
+ & RangeOperand {
359
+ operand : lhs,
360
+ span : lspan,
361
+ } ,
362
+ & RangeOperand {
363
+ operand : rhs,
364
+ span : rspan,
365
+ } ,
366
+ PairParts :: infix ( & infix) ,
367
+ context,
368
+ shape,
369
+ SeparatorPlace :: Front ,
370
+ )
371
+ }
372
+
362
373
fn rewrite_struct_pat (
363
374
qself : & Option < ptr:: P < ast:: QSelf > > ,
364
375
path : & ast:: Path ,
0 commit comments