@@ -266,55 +266,54 @@ fn rewrite_tuple_pat(pats: &[ptr::P<ast::Pat>],
266
266
}
267
267
268
268
if pat_vec. is_empty ( ) {
269
- path_str
269
+ return Some ( format ! ( "{}()" , try_opt!( path_str) ) ) ;
270
+ }
271
+ // add comma if `(x,)`
272
+ let add_comma = path_str. is_none ( ) && pat_vec. len ( ) == 1 && dotdot_pos. is_none ( ) ;
273
+
274
+ let path_len = path_str. as_ref ( ) . map ( |p| p. len ( ) ) . unwrap_or ( 0 ) ;
275
+ // 2 = "()".len(), 3 = "(,)".len()
276
+ let nested_shape = try_opt ! ( shape. sub_width( path_len + if add_comma { 3 } else { 2 } ) ) ;
277
+ // 1 = "(".len()
278
+ let nested_shape = nested_shape. visual_indent ( path_len + 1 ) ;
279
+ let mut items: Vec < _ > = itemize_list ( context. codemap ,
280
+ pat_vec. iter ( ) ,
281
+ if add_comma { ",)" } else { ")" } ,
282
+ |item| item. span ( ) . lo ,
283
+ |item| item. span ( ) . hi ,
284
+ |item| item. rewrite ( context, nested_shape) ,
285
+ context. codemap . span_after ( span, "(" ) ,
286
+ span. hi - BytePos ( 1 ) )
287
+ . collect ( ) ;
288
+
289
+ // Condense wildcard string suffix into a single ..
290
+ let wildcard_suffix_len = count_wildcard_suffix_len ( & items) ;
291
+
292
+ let list = if context. config . condense_wildcard_suffices && wildcard_suffix_len >= 2 {
293
+ let new_item_count = 1 + pats. len ( ) - wildcard_suffix_len;
294
+ items[ new_item_count - 1 ] . item = Some ( ".." . to_owned ( ) ) ;
295
+
296
+ let da_iter = items. into_iter ( ) . take ( new_item_count) ;
297
+ try_opt ! ( format_item_list( da_iter, nested_shape, context. config) )
270
298
} else {
271
- // add comma if `(x,)`
272
- let add_comma = path_str. is_none ( ) && pat_vec. len ( ) == 1 && dotdot_pos. is_none ( ) ;
273
-
274
- let path_len = path_str. as_ref ( ) . map ( |p| p. len ( ) ) . unwrap_or ( 0 ) ;
275
- // 2 = "()".len(), 3 = "(,)".len()
276
- let nested_shape = try_opt ! ( shape. sub_width( path_len + if add_comma { 3 } else { 2 } ) ) ;
277
- // 1 = "(".len()
278
- let nested_shape = nested_shape. visual_indent ( path_len + 1 ) ;
279
- let mut items: Vec < _ > = itemize_list ( context. codemap ,
280
- pat_vec. iter ( ) ,
281
- if add_comma { ",)" } else { ")" } ,
282
- |item| item. span ( ) . lo ,
283
- |item| item. span ( ) . hi ,
284
- |item| item. rewrite ( context, nested_shape) ,
285
- context. codemap . span_after ( span, "(" ) ,
286
- span. hi - BytePos ( 1 ) )
287
- . collect ( ) ;
288
-
289
- // Condense wildcard string suffix into a single ..
290
- let wildcard_suffix_len = count_wildcard_suffix_len ( & items) ;
291
-
292
- let list = if context. config . condense_wildcard_suffices && wildcard_suffix_len >= 2 {
293
- let new_item_count = 1 + pats. len ( ) - wildcard_suffix_len;
294
- items[ new_item_count - 1 ] . item = Some ( ".." . to_owned ( ) ) ;
295
-
296
- let da_iter = items. into_iter ( ) . take ( new_item_count) ;
297
- try_opt ! ( format_item_list( da_iter, nested_shape, context. config) )
298
- } else {
299
- try_opt ! ( format_item_list( items. into_iter( ) , nested_shape, context. config) )
300
- } ;
299
+ try_opt ! ( format_item_list( items. into_iter( ) , nested_shape, context. config) )
300
+ } ;
301
301
302
- match path_str {
303
- Some ( path_str) => {
304
- Some ( if context. config . spaces_within_parens {
305
- format ! ( "{}( {} )" , path_str, list)
306
- } else {
307
- format ! ( "{}({})" , path_str, list)
308
- } )
309
- }
310
- None => {
311
- let comma = if add_comma { "," } else { "" } ;
312
- Some ( if context. config . spaces_within_parens {
313
- format ! ( "( {}{} )" , list, comma)
314
- } else {
315
- format ! ( "({}{})" , list, comma)
316
- } )
317
- }
302
+ match path_str {
303
+ Some ( path_str) => {
304
+ Some ( if context. config . spaces_within_parens {
305
+ format ! ( "{}( {} )" , path_str, list)
306
+ } else {
307
+ format ! ( "{}({})" , path_str, list)
308
+ } )
309
+ }
310
+ None => {
311
+ let comma = if add_comma { "," } else { "" } ;
312
+ Some ( if context. config . spaces_within_parens {
313
+ format ! ( "( {}{} )" , list, comma)
314
+ } else {
315
+ format ! ( "({}{})" , list, comma)
316
+ } )
318
317
}
319
318
}
320
319
}
0 commit comments