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