@@ -3,7 +3,7 @@ use std::cmp::min;
3
3
4
4
use itertools:: Itertools ;
5
5
use rustc_ast:: token:: { Delimiter , LitKind } ;
6
- use rustc_ast:: { ast, ptr} ;
6
+ use rustc_ast:: { ast, ptr, token } ;
7
7
use rustc_span:: { BytePos , Span } ;
8
8
9
9
use crate :: chains:: rewrite_chain;
@@ -75,12 +75,12 @@ pub(crate) fn format_expr(
75
75
choose_separator_tactic ( context, expr. span ) ,
76
76
None ,
77
77
) ,
78
- ast:: ExprKind :: Lit ( ref l ) => {
79
- if let Some ( expr_rw) = rewrite_literal ( context, l , shape) {
78
+ ast:: ExprKind :: Lit ( token_lit ) => {
79
+ if let Some ( expr_rw) = rewrite_literal ( context, token_lit , expr . span , shape) {
80
80
Some ( expr_rw)
81
81
} else {
82
- if let LitKind :: StrRaw ( _) = l . token_lit . kind {
83
- Some ( context. snippet ( l . span ) . trim ( ) . into ( ) )
82
+ if let LitKind :: StrRaw ( _) = token_lit. kind {
83
+ Some ( context. snippet ( expr . span ) . trim ( ) . into ( ) )
84
84
} else {
85
85
None
86
86
}
@@ -274,9 +274,9 @@ pub(crate) fn format_expr(
274
274
275
275
fn needs_space_before_range ( context : & RewriteContext < ' _ > , lhs : & ast:: Expr ) -> bool {
276
276
match lhs. kind {
277
- ast:: ExprKind :: Lit ( ref lit ) => match lit . kind {
278
- ast :: LitKind :: Float ( _ , ast :: LitFloatType :: Unsuffixed ) => {
279
- context. snippet ( lit . span ) . ends_with ( '.' )
277
+ ast:: ExprKind :: Lit ( token_lit ) => match token_lit . kind {
278
+ token :: LitKind :: Float if token_lit . suffix . is_none ( ) => {
279
+ context. snippet ( lhs . span ) . ends_with ( '.' )
280
280
}
281
281
_ => false ,
282
282
} ,
@@ -1185,14 +1185,15 @@ pub(crate) fn is_unsafe_block(block: &ast::Block) -> bool {
1185
1185
1186
1186
pub ( crate ) fn rewrite_literal (
1187
1187
context : & RewriteContext < ' _ > ,
1188
- l : & ast:: Lit ,
1188
+ token_lit : token:: Lit ,
1189
+ span : Span ,
1189
1190
shape : Shape ,
1190
1191
) -> Option < String > {
1191
- match l . kind {
1192
- ast :: LitKind :: Str ( _ , ast :: StrStyle :: Cooked ) => rewrite_string_lit ( context, l . span , shape) ,
1193
- ast :: LitKind :: Int ( .. ) => rewrite_int_lit ( context, l , shape) ,
1192
+ match token_lit . kind {
1193
+ token :: LitKind :: Str => rewrite_string_lit ( context, span, shape) ,
1194
+ token :: LitKind :: Integer => rewrite_int_lit ( context, token_lit , span , shape) ,
1194
1195
_ => wrap_str (
1195
- context. snippet ( l . span ) . to_owned ( ) ,
1196
+ context. snippet ( span) . to_owned ( ) ,
1196
1197
context. config . max_width ( ) ,
1197
1198
shape,
1198
1199
) ,
@@ -1225,9 +1226,13 @@ fn rewrite_string_lit(context: &RewriteContext<'_>, span: Span, shape: Shape) ->
1225
1226
)
1226
1227
}
1227
1228
1228
- fn rewrite_int_lit ( context : & RewriteContext < ' _ > , lit : & ast:: Lit , shape : Shape ) -> Option < String > {
1229
- let span = lit. span ;
1230
- let symbol = lit. token_lit . symbol . as_str ( ) ;
1229
+ fn rewrite_int_lit (
1230
+ context : & RewriteContext < ' _ > ,
1231
+ token_lit : token:: Lit ,
1232
+ span : Span ,
1233
+ shape : Shape ,
1234
+ ) -> Option < String > {
1235
+ let symbol = token_lit. symbol . as_str ( ) ;
1231
1236
1232
1237
if let Some ( symbol_stripped) = symbol. strip_prefix ( "0x" ) {
1233
1238
let hex_lit = match context. config . hex_literal_case ( ) {
@@ -1240,9 +1245,7 @@ fn rewrite_int_lit(context: &RewriteContext<'_>, lit: &ast::Lit, shape: Shape) -
1240
1245
format ! (
1241
1246
"0x{}{}" ,
1242
1247
hex_lit,
1243
- lit. token_lit
1244
- . suffix
1245
- . map_or( String :: new( ) , |s| s. to_string( ) )
1248
+ token_lit. suffix. map_or( String :: new( ) , |s| s. to_string( ) )
1246
1249
) ,
1247
1250
context. config . max_width ( ) ,
1248
1251
shape,
0 commit comments