@@ -79,7 +79,8 @@ pub(crate) fn format_expr(
79
79
shape,
80
80
choose_separator_tactic ( context, expr. span ) ,
81
81
None ,
82
- ) ,
82
+ )
83
+ . ok ( ) ,
83
84
ast:: ExprKind :: Lit ( token_lit) => {
84
85
if let Some ( expr_rw) = rewrite_literal ( context, token_lit, expr. span , shape) {
85
86
Some ( expr_rw)
@@ -94,21 +95,23 @@ pub(crate) fn format_expr(
94
95
ast:: ExprKind :: Call ( ref callee, ref args) => {
95
96
let inner_span = mk_sp ( callee. span . hi ( ) , expr. span . hi ( ) ) ;
96
97
let callee_str = callee. rewrite ( context, shape) ?;
97
- rewrite_call ( context, & callee_str, args, inner_span, shape)
98
+ rewrite_call ( context, & callee_str, args, inner_span, shape) . ok ( )
98
99
}
99
100
ast:: ExprKind :: Paren ( ref subexpr) => rewrite_paren ( context, subexpr, shape, expr. span ) ,
100
101
ast:: ExprKind :: Binary ( op, ref lhs, ref rhs) => {
101
102
// FIXME: format comments between operands and operator
102
- rewrite_all_pairs ( expr, shape, context) . or_else ( || {
103
- rewrite_pair (
104
- & * * lhs,
105
- & * * rhs,
106
- PairParts :: infix ( & format ! ( " {} " , context. snippet( op. span) ) ) ,
107
- context,
108
- shape,
109
- context. config . binop_separator ( ) ,
110
- )
111
- } )
103
+ rewrite_all_pairs ( expr, shape, context)
104
+ . or_else ( |_| {
105
+ rewrite_pair (
106
+ & * * lhs,
107
+ & * * rhs,
108
+ PairParts :: infix ( & format ! ( " {} " , context. snippet( op. span) ) ) ,
109
+ context,
110
+ shape,
111
+ context. config . binop_separator ( ) ,
112
+ )
113
+ } )
114
+ . ok ( )
112
115
}
113
116
ast:: ExprKind :: Unary ( op, ref subexpr) => rewrite_unary_op ( context, op, subexpr, shape) ,
114
117
ast:: ExprKind :: Struct ( ref struct_expr) => {
@@ -131,7 +134,7 @@ pub(crate) fn format_expr(
131
134
. ok ( )
132
135
}
133
136
ast:: ExprKind :: Tup ( ref items) => {
134
- rewrite_tuple ( context, items. iter ( ) , expr. span , shape, items. len ( ) == 1 )
137
+ rewrite_tuple ( context, items. iter ( ) , expr. span , shape, items. len ( ) == 1 ) . ok ( )
135
138
}
136
139
ast:: ExprKind :: Let ( ref pat, ref expr, _span, _) => rewrite_let ( context, shape, pat, expr) ,
137
140
ast:: ExprKind :: If ( ..)
@@ -265,7 +268,8 @@ pub(crate) fn format_expr(
265
268
context,
266
269
shape,
267
270
SeparatorPlace :: Front ,
268
- ) ,
271
+ )
272
+ . ok ( ) ,
269
273
ast:: ExprKind :: Index ( ref expr, ref index, _) => {
270
274
rewrite_index ( & * * expr, & * * index, context, shape)
271
275
}
@@ -276,7 +280,8 @@ pub(crate) fn format_expr(
276
280
context,
277
281
shape,
278
282
SeparatorPlace :: Back ,
279
- ) ,
283
+ )
284
+ . ok ( ) ,
280
285
ast:: ExprKind :: Range ( ref lhs, ref rhs, limits) => {
281
286
let delim = match limits {
282
287
ast:: RangeLimits :: HalfOpen => ".." ,
@@ -329,6 +334,7 @@ pub(crate) fn format_expr(
329
334
shape,
330
335
context. config . binop_separator ( ) ,
331
336
)
337
+ . ok ( )
332
338
}
333
339
( None , Some ( rhs) ) => {
334
340
let sp_delim = if context. config . spaces_around_ranges ( ) {
@@ -442,7 +448,7 @@ pub(crate) fn rewrite_array<'a, T: 'a + IntoOverflowableItem<'a>>(
442
448
shape : Shape ,
443
449
force_separator_tactic : Option < SeparatorTactic > ,
444
450
delim_token : Option < Delimiter > ,
445
- ) -> Option < String > {
451
+ ) -> RewriteResult {
446
452
overflow:: rewrite_with_square_brackets (
447
453
context,
448
454
name,
@@ -1346,7 +1352,7 @@ pub(crate) fn rewrite_call(
1346
1352
args : & [ ptr:: P < ast:: Expr > ] ,
1347
1353
span : Span ,
1348
1354
shape : Shape ,
1349
- ) -> Option < String > {
1355
+ ) -> RewriteResult {
1350
1356
overflow:: rewrite_with_parens (
1351
1357
context,
1352
1358
callee,
@@ -1830,21 +1836,27 @@ fn rewrite_tuple_in_visual_indent_style<'a, T: 'a + IntoOverflowableItem<'a>>(
1830
1836
span : Span ,
1831
1837
shape : Shape ,
1832
1838
is_singleton_tuple : bool ,
1833
- ) -> Option < String > {
1839
+ ) -> RewriteResult {
1834
1840
// In case of length 1, need a trailing comma
1835
1841
debug ! ( "rewrite_tuple_in_visual_indent_style {:?}" , shape) ;
1836
1842
if is_singleton_tuple {
1837
1843
// 3 = "(" + ",)"
1838
- let nested_shape = shape. sub_width ( 3 ) ?. visual_indent ( 1 ) ;
1844
+ let nested_shape = shape
1845
+ . sub_width ( 3 )
1846
+ . max_width_error ( shape. width , span) ?
1847
+ . visual_indent ( 1 ) ;
1839
1848
return items
1840
1849
. next ( )
1841
1850
. unwrap ( )
1842
- . rewrite ( context, nested_shape)
1851
+ . rewrite_result ( context, nested_shape)
1843
1852
. map ( |s| format ! ( "({},)" , s) ) ;
1844
1853
}
1845
1854
1846
1855
let list_lo = context. snippet_provider . span_after ( span, "(" ) ;
1847
- let nested_shape = shape. sub_width ( 2 ) ?. visual_indent ( 1 ) ;
1856
+ let nested_shape = shape
1857
+ . sub_width ( 2 )
1858
+ . max_width_error ( shape. width , span) ?
1859
+ . visual_indent ( 1 ) ;
1848
1860
let items = itemize_list (
1849
1861
context. snippet_provider ,
1850
1862
items,
@@ -1867,9 +1879,9 @@ fn rewrite_tuple_in_visual_indent_style<'a, T: 'a + IntoOverflowableItem<'a>>(
1867
1879
let fmt = ListFormatting :: new ( nested_shape, context. config )
1868
1880
. tactic ( tactic)
1869
1881
. ends_with_newline ( false ) ;
1870
- let list_str = write_list ( & item_vec, & fmt) . ok ( ) ?;
1882
+ let list_str = write_list ( & item_vec, & fmt) ?;
1871
1883
1872
- Some ( format ! ( "({list_str})" ) )
1884
+ Ok ( format ! ( "({list_str})" ) )
1873
1885
}
1874
1886
1875
1887
fn rewrite_let (
@@ -1912,7 +1924,7 @@ pub(crate) fn rewrite_tuple<'a, T: 'a + IntoOverflowableItem<'a>>(
1912
1924
span : Span ,
1913
1925
shape : Shape ,
1914
1926
is_singleton_tuple : bool ,
1915
- ) -> Option < String > {
1927
+ ) -> RewriteResult {
1916
1928
debug ! ( "rewrite_tuple {:?}" , shape) ;
1917
1929
if context. use_block_indent ( ) {
1918
1930
// We use the same rule as function calls for rewriting tuples.
0 commit comments