@@ -97,7 +97,7 @@ pub(crate) fn format_expr(
97
97
let callee_str = callee. rewrite ( context, shape) ?;
98
98
rewrite_call ( context, & callee_str, args, inner_span, shape) . ok ( )
99
99
}
100
- ast:: ExprKind :: Paren ( ref subexpr) => rewrite_paren ( context, subexpr, shape, expr. span ) ,
100
+ ast:: ExprKind :: Paren ( ref subexpr) => rewrite_paren ( context, subexpr, shape, expr. span ) . ok ( ) ,
101
101
ast:: ExprKind :: Binary ( op, ref lhs, ref rhs) => {
102
102
// FIXME: format comments between operands and operator
103
103
rewrite_all_pairs ( expr, shape, context)
@@ -1484,7 +1484,7 @@ pub(crate) fn rewrite_paren(
1484
1484
mut subexpr : & ast:: Expr ,
1485
1485
shape : Shape ,
1486
1486
mut span : Span ,
1487
- ) -> Option < String > {
1487
+ ) -> RewriteResult {
1488
1488
debug ! ( "rewrite_paren, shape: {:?}" , shape) ;
1489
1489
1490
1490
// Extract comments within parens.
@@ -1497,8 +1497,8 @@ pub(crate) fn rewrite_paren(
1497
1497
// 1 = "(" or ")"
1498
1498
pre_span = mk_sp ( span. lo ( ) + BytePos ( 1 ) , subexpr. span ( ) . lo ( ) ) ;
1499
1499
post_span = mk_sp ( subexpr. span . hi ( ) , span. hi ( ) - BytePos ( 1 ) ) ;
1500
- pre_comment = rewrite_missing_comment ( pre_span, shape, context) . ok ( ) ?;
1501
- post_comment = rewrite_missing_comment ( post_span, shape, context) . ok ( ) ?;
1500
+ pre_comment = rewrite_missing_comment ( pre_span, shape, context) ?;
1501
+ post_comment = rewrite_missing_comment ( post_span, shape, context) ?;
1502
1502
1503
1503
// Remove nested parens if there are no comments.
1504
1504
if let ast:: ExprKind :: Paren ( ref subsubexpr) = subexpr. kind {
@@ -1513,11 +1513,14 @@ pub(crate) fn rewrite_paren(
1513
1513
}
1514
1514
1515
1515
// 1 = `(` and `)`
1516
- let sub_shape = shape. offset_left ( 1 ) ?. sub_width ( 1 ) ?;
1517
- let subexpr_str = subexpr. rewrite ( context, sub_shape) ?;
1516
+ let sub_shape = shape
1517
+ . offset_left ( 1 )
1518
+ . and_then ( |s| s. sub_width ( 1 ) )
1519
+ . max_width_error ( shape. width , span) ?;
1520
+ let subexpr_str = subexpr. rewrite_result ( context, sub_shape) ?;
1518
1521
let fits_single_line = !pre_comment. contains ( "//" ) && !post_comment. contains ( "//" ) ;
1519
1522
if fits_single_line {
1520
- Some ( format ! ( "({pre_comment}{subexpr_str}{post_comment})" ) )
1523
+ Ok ( format ! ( "({pre_comment}{subexpr_str}{post_comment})" ) )
1521
1524
} else {
1522
1525
rewrite_paren_in_multi_line ( context, subexpr, shape, pre_span, post_span)
1523
1526
}
@@ -1529,12 +1532,12 @@ fn rewrite_paren_in_multi_line(
1529
1532
shape : Shape ,
1530
1533
pre_span : Span ,
1531
1534
post_span : Span ,
1532
- ) -> Option < String > {
1535
+ ) -> RewriteResult {
1533
1536
let nested_indent = shape. indent . block_indent ( context. config ) ;
1534
1537
let nested_shape = Shape :: indented ( nested_indent, context. config ) ;
1535
- let pre_comment = rewrite_missing_comment ( pre_span, nested_shape, context) . ok ( ) ?;
1536
- let post_comment = rewrite_missing_comment ( post_span, nested_shape, context) . ok ( ) ?;
1537
- let subexpr_str = subexpr. rewrite ( context, nested_shape) ?;
1538
+ let pre_comment = rewrite_missing_comment ( pre_span, nested_shape, context) ?;
1539
+ let post_comment = rewrite_missing_comment ( post_span, nested_shape, context) ?;
1540
+ let subexpr_str = subexpr. rewrite_result ( context, nested_shape) ?;
1538
1541
1539
1542
let mut result = String :: with_capacity ( subexpr_str. len ( ) * 2 ) ;
1540
1543
result. push ( '(' ) ;
@@ -1551,7 +1554,7 @@ fn rewrite_paren_in_multi_line(
1551
1554
result. push_str ( & shape. indent . to_string_with_newline ( context. config ) ) ;
1552
1555
result. push ( ')' ) ;
1553
1556
1554
- Some ( result)
1557
+ Ok ( result)
1555
1558
}
1556
1559
1557
1560
fn rewrite_index (
0 commit comments