@@ -1444,10 +1444,6 @@ fn rewrite_match(
1444
1444
span : Span ,
1445
1445
attrs : & [ ast:: Attribute ] ,
1446
1446
) -> Option < String > {
1447
- if arms. is_empty ( ) {
1448
- return None ;
1449
- }
1450
-
1451
1447
// Do not take the rhs overhead from the upper expressions into account
1452
1448
// when rewriting match condition.
1453
1449
let cond_shape = Shape {
@@ -1484,9 +1480,12 @@ fn rewrite_match(
1484
1480
} ;
1485
1481
1486
1482
let open_brace_pos = if inner_attrs. is_empty ( ) {
1487
- context
1488
- . codemap
1489
- . span_after ( mk_sp ( cond. span . hi ( ) , arms[ 0 ] . span ( ) . lo ( ) ) , "{" )
1483
+ let hi = if arms. is_empty ( ) {
1484
+ span. hi ( )
1485
+ } else {
1486
+ arms[ 0 ] . span ( ) . lo ( )
1487
+ } ;
1488
+ context. codemap . span_after ( mk_sp ( cond. span . hi ( ) , hi) , "{" )
1490
1489
} else {
1491
1490
inner_attrs[ inner_attrs. len ( ) - 1 ] . span ( ) . hi ( )
1492
1491
} ;
@@ -1497,15 +1496,25 @@ fn rewrite_match(
1497
1496
shape. indent . to_string ( context. config )
1498
1497
} ;
1499
1498
1500
- Some ( format ! (
1501
- "match {}{}{{\n {}{}{}\n {}}}" ,
1502
- cond_str,
1503
- block_sep,
1504
- inner_attrs_str,
1505
- arm_indent_str,
1506
- rewrite_match_arms( context, arms, shape, span, open_brace_pos, ) ?,
1507
- shape. indent. to_string( context. config) ,
1508
- ) )
1499
+ if arms. is_empty ( ) {
1500
+ let snippet = context. snippet ( mk_sp ( open_brace_pos, span. hi ( ) - BytePos ( 1 ) ) ) ;
1501
+ if snippet. trim ( ) . is_empty ( ) {
1502
+ Some ( format ! ( "match {} {{}}" , cond_str) )
1503
+ } else {
1504
+ // Empty match with comments or inner attributes? We are not going to bother, sorry ;)
1505
+ Some ( context. snippet ( span) )
1506
+ }
1507
+ } else {
1508
+ Some ( format ! (
1509
+ "match {}{}{{\n {}{}{}\n {}}}" ,
1510
+ cond_str,
1511
+ block_sep,
1512
+ inner_attrs_str,
1513
+ arm_indent_str,
1514
+ rewrite_match_arms( context, arms, shape, span, open_brace_pos) ?,
1515
+ shape. indent. to_string( context. config) ,
1516
+ ) )
1517
+ }
1509
1518
}
1510
1519
1511
1520
fn arm_comma ( config : & Config , body : & ast:: Expr , is_last : bool ) -> & ' static str {
0 commit comments