@@ -97,7 +97,7 @@ pub(crate) fn format_expr(
9797 let callee_str = callee. rewrite ( context, shape) ?;
9898 rewrite_call ( context, & callee_str, args, inner_span, shape) . ok ( )
9999 }
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 ( ) ,
101101 ast:: ExprKind :: Binary ( op, ref lhs, ref rhs) => {
102102 // FIXME: format comments between operands and operator
103103 rewrite_all_pairs ( expr, shape, context)
@@ -1484,7 +1484,7 @@ pub(crate) fn rewrite_paren(
14841484 mut subexpr : & ast:: Expr ,
14851485 shape : Shape ,
14861486 mut span : Span ,
1487- ) -> Option < String > {
1487+ ) -> RewriteResult {
14881488 debug ! ( "rewrite_paren, shape: {:?}" , shape) ;
14891489
14901490 // Extract comments within parens.
@@ -1497,8 +1497,8 @@ pub(crate) fn rewrite_paren(
14971497 // 1 = "(" or ")"
14981498 pre_span = mk_sp ( span. lo ( ) + BytePos ( 1 ) , subexpr. span ( ) . lo ( ) ) ;
14991499 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) ?;
15021502
15031503 // Remove nested parens if there are no comments.
15041504 if let ast:: ExprKind :: Paren ( ref subsubexpr) = subexpr. kind {
@@ -1513,11 +1513,14 @@ pub(crate) fn rewrite_paren(
15131513 }
15141514
15151515 // 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) ?;
15181521 let fits_single_line = !pre_comment. contains ( "//" ) && !post_comment. contains ( "//" ) ;
15191522 if fits_single_line {
1520- Some ( format ! ( "({pre_comment}{subexpr_str}{post_comment})" ) )
1523+ Ok ( format ! ( "({pre_comment}{subexpr_str}{post_comment})" ) )
15211524 } else {
15221525 rewrite_paren_in_multi_line ( context, subexpr, shape, pre_span, post_span)
15231526 }
@@ -1529,12 +1532,12 @@ fn rewrite_paren_in_multi_line(
15291532 shape : Shape ,
15301533 pre_span : Span ,
15311534 post_span : Span ,
1532- ) -> Option < String > {
1535+ ) -> RewriteResult {
15331536 let nested_indent = shape. indent . block_indent ( context. config ) ;
15341537 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) ?;
15381541
15391542 let mut result = String :: with_capacity ( subexpr_str. len ( ) * 2 ) ;
15401543 result. push ( '(' ) ;
@@ -1551,7 +1554,7 @@ fn rewrite_paren_in_multi_line(
15511554 result. push_str ( & shape. indent . to_string_with_newline ( context. config ) ) ;
15521555 result. push ( ')' ) ;
15531556
1554- Some ( result)
1557+ Ok ( result)
15551558}
15561559
15571560fn rewrite_index (
0 commit comments