@@ -82,7 +82,7 @@ pub(crate) fn format_expr(
82
82
)
83
83
. ok ( ) ,
84
84
ast:: ExprKind :: Lit ( token_lit) => {
85
- if let Some ( expr_rw) = rewrite_literal ( context, token_lit, expr. span , shape) {
85
+ if let Ok ( expr_rw) = rewrite_literal ( context, token_lit, expr. span , shape) {
86
86
Some ( expr_rw)
87
87
} else {
88
88
if let LitKind :: StrRaw ( _) = token_lit. kind {
@@ -1262,19 +1262,20 @@ pub(crate) fn rewrite_literal(
1262
1262
token_lit : token:: Lit ,
1263
1263
span : Span ,
1264
1264
shape : Shape ,
1265
- ) -> Option < String > {
1265
+ ) -> RewriteResult {
1266
1266
match token_lit. kind {
1267
1267
token:: LitKind :: Str => rewrite_string_lit ( context, span, shape) ,
1268
1268
token:: LitKind :: Integer => rewrite_int_lit ( context, token_lit, span, shape) ,
1269
1269
_ => wrap_str (
1270
1270
context. snippet ( span) . to_owned ( ) ,
1271
1271
context. config . max_width ( ) ,
1272
1272
shape,
1273
- ) ,
1273
+ )
1274
+ . max_width_error ( shape. width , span) ,
1274
1275
}
1275
1276
}
1276
1277
1277
- fn rewrite_string_lit ( context : & RewriteContext < ' _ > , span : Span , shape : Shape ) -> Option < String > {
1278
+ fn rewrite_string_lit ( context : & RewriteContext < ' _ > , span : Span , shape : Shape ) -> RewriteResult {
1278
1279
let string_lit = context. snippet ( span) ;
1279
1280
1280
1281
if !context. config . format_strings ( ) {
@@ -1284,9 +1285,10 @@ fn rewrite_string_lit(context: &RewriteContext<'_>, span: Span, shape: Shape) ->
1284
1285
. all ( |line| line. ends_with ( '\\' ) )
1285
1286
&& context. config . style_edition ( ) >= StyleEdition :: Edition2024
1286
1287
{
1287
- return Some ( string_lit. to_owned ( ) ) ;
1288
+ return Ok ( string_lit. to_owned ( ) ) ;
1288
1289
} else {
1289
- return wrap_str ( string_lit. to_owned ( ) , context. config . max_width ( ) , shape) ;
1290
+ return wrap_str ( string_lit. to_owned ( ) , context. config . max_width ( ) , shape)
1291
+ . max_width_error ( shape. width , span) ;
1290
1292
}
1291
1293
}
1292
1294
@@ -1298,14 +1300,15 @@ fn rewrite_string_lit(context: &RewriteContext<'_>, span: Span, shape: Shape) ->
1298
1300
& StringFormat :: new ( shape. visual_indent ( 0 ) , context. config ) ,
1299
1301
shape. width . saturating_sub ( 2 ) ,
1300
1302
)
1303
+ . max_width_error ( shape. width , span) // - 2 ?
1301
1304
}
1302
1305
1303
1306
fn rewrite_int_lit (
1304
1307
context : & RewriteContext < ' _ > ,
1305
1308
token_lit : token:: Lit ,
1306
1309
span : Span ,
1307
1310
shape : Shape ,
1308
- ) -> Option < String > {
1311
+ ) -> RewriteResult {
1309
1312
let symbol = token_lit. symbol . as_str ( ) ;
1310
1313
1311
1314
if let Some ( symbol_stripped) = symbol. strip_prefix ( "0x" ) {
@@ -1323,7 +1326,8 @@ fn rewrite_int_lit(
1323
1326
) ,
1324
1327
context. config . max_width ( ) ,
1325
1328
shape,
1326
- ) ;
1329
+ )
1330
+ . max_width_error ( shape. width , span) ;
1327
1331
}
1328
1332
}
1329
1333
@@ -1332,6 +1336,7 @@ fn rewrite_int_lit(
1332
1336
context. config . max_width ( ) ,
1333
1337
shape,
1334
1338
)
1339
+ . max_width_error ( shape. width , span)
1335
1340
}
1336
1341
1337
1342
fn choose_separator_tactic ( context : & RewriteContext < ' _ > , span : Span ) -> Option < SeparatorTactic > {
0 commit comments