@@ -54,8 +54,11 @@ pub(crate) enum ExprType {
54
54
SubExpression ,
55
55
}
56
56
57
- pub ( crate ) fn lit_ends_in_dot ( lit : & Lit ) -> bool {
58
- matches ! ( lit, Lit { kind: LitKind :: Float , suffix: None , symbol } if symbol. as_str( ) . ends_with( '.' ) )
57
+ pub ( crate ) fn lit_ends_in_dot ( lit : & Lit , context : & RewriteContext < ' _ > ) -> bool {
58
+ match lit. kind {
59
+ LitKind :: Float => do_rewrite_float_lit ( context, * lit) . ends_with ( '.' ) ,
60
+ _ => false ,
61
+ }
59
62
}
60
63
61
64
pub ( crate ) fn format_expr (
@@ -297,7 +300,7 @@ pub(crate) fn format_expr(
297
300
298
301
fn needs_space_before_range ( context : & RewriteContext < ' _ > , lhs : & ast:: Expr ) -> bool {
299
302
match lhs. kind {
300
- ast:: ExprKind :: Lit ( token_lit) => lit_ends_in_dot ( & token_lit) ,
303
+ ast:: ExprKind :: Lit ( token_lit) => lit_ends_in_dot ( & token_lit, context ) ,
301
304
ast:: ExprKind :: Unary ( _, ref expr) => needs_space_before_range ( context, expr) ,
302
305
ast:: ExprKind :: Binary ( _, _, ref rhs_expr) => {
303
306
needs_space_before_range ( context, rhs_expr)
@@ -1350,27 +1353,17 @@ fn rewrite_int_lit(
1350
1353
. max_width_error ( shape. width , span)
1351
1354
}
1352
1355
1353
- fn rewrite_float_lit (
1354
- context : & RewriteContext < ' _ > ,
1355
- token_lit : token:: Lit ,
1356
- span : Span ,
1357
- shape : Shape ,
1358
- ) -> RewriteResult {
1356
+ fn do_rewrite_float_lit ( context : & RewriteContext < ' _ > , token_lit : token:: Lit ) -> String {
1357
+ let symbol = token_lit. symbol . as_str ( ) ;
1358
+ let suffix = token_lit. suffix . as_ref ( ) . map ( |s| s. as_str ( ) ) ;
1359
+
1359
1360
if matches ! (
1360
1361
context. config. float_literal_trailing_zero( ) ,
1361
1362
FloatLiteralTrailingZero :: Preserve
1362
1363
) {
1363
- return wrap_str (
1364
- context. snippet ( span) . to_owned ( ) ,
1365
- context. config . max_width ( ) ,
1366
- shape,
1367
- )
1368
- . max_width_error ( shape. width , span) ;
1364
+ return format ! ( "{}{}" , symbol, suffix. unwrap_or( "" ) ) ;
1369
1365
}
1370
1366
1371
- let symbol = token_lit. symbol . as_str ( ) ;
1372
- let suffix = token_lit. suffix . as_ref ( ) . map ( |s| s. as_str ( ) ) ;
1373
-
1374
1367
let FloatSymbolParts {
1375
1368
integer_part,
1376
1369
fractional_part,
@@ -1400,15 +1393,24 @@ fn rewrite_float_lit(
1400
1393
} else {
1401
1394
""
1402
1395
} ;
1396
+ format ! (
1397
+ "{}{}{}{}{}" ,
1398
+ integer_part,
1399
+ period,
1400
+ fractional_part,
1401
+ exponent. unwrap_or( "" ) ,
1402
+ suffix. unwrap_or( "" ) ,
1403
+ )
1404
+ }
1405
+
1406
+ fn rewrite_float_lit (
1407
+ context : & RewriteContext < ' _ > ,
1408
+ token_lit : token:: Lit ,
1409
+ span : Span ,
1410
+ shape : Shape ,
1411
+ ) -> RewriteResult {
1403
1412
wrap_str (
1404
- format ! (
1405
- "{}{}{}{}{}" ,
1406
- integer_part,
1407
- period,
1408
- fractional_part,
1409
- exponent. unwrap_or( "" ) ,
1410
- suffix. unwrap_or( "" ) ,
1411
- ) ,
1413
+ do_rewrite_float_lit ( context, token_lit) ,
1412
1414
context. config . max_width ( ) ,
1413
1415
shape,
1414
1416
)
0 commit comments