@@ -3,7 +3,7 @@ use std::cmp::min;
33
44use itertools:: Itertools ;
55use rustc_ast:: token:: { Delimiter , LitKind } ;
6- use rustc_ast:: { ast, ptr} ;
6+ use rustc_ast:: { ast, ptr, token } ;
77use rustc_span:: { BytePos , Span } ;
88
99use crate :: chains:: rewrite_chain;
@@ -75,12 +75,12 @@ pub(crate) fn format_expr(
7575 choose_separator_tactic ( context, expr. span ) ,
7676 None ,
7777 ) ,
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) {
8080 Some ( expr_rw)
8181 } 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 ( ) )
8484 } else {
8585 None
8686 }
@@ -274,9 +274,9 @@ pub(crate) fn format_expr(
274274
275275 fn needs_space_before_range ( context : & RewriteContext < ' _ > , lhs : & ast:: Expr ) -> bool {
276276 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 ( '.' )
280280 }
281281 _ => false ,
282282 } ,
@@ -1185,14 +1185,15 @@ pub(crate) fn is_unsafe_block(block: &ast::Block) -> bool {
11851185
11861186pub ( crate ) fn rewrite_literal (
11871187 context : & RewriteContext < ' _ > ,
1188- l : & ast:: Lit ,
1188+ token_lit : token:: Lit ,
1189+ span : Span ,
11891190 shape : Shape ,
11901191) -> 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) ,
11941195 _ => wrap_str (
1195- context. snippet ( l . span ) . to_owned ( ) ,
1196+ context. snippet ( span) . to_owned ( ) ,
11961197 context. config . max_width ( ) ,
11971198 shape,
11981199 ) ,
@@ -1225,9 +1226,13 @@ fn rewrite_string_lit(context: &RewriteContext<'_>, span: Span, shape: Shape) ->
12251226 )
12261227}
12271228
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 ( ) ;
12311236
12321237 if let Some ( symbol_stripped) = symbol. strip_prefix ( "0x" ) {
12331238 let hex_lit = match context. config . hex_literal_case ( ) {
@@ -1240,9 +1245,7 @@ fn rewrite_int_lit(context: &RewriteContext<'_>, lit: &ast::Lit, shape: Shape) -
12401245 format ! (
12411246 "0x{}{}" ,
12421247 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( ) )
12461249 ) ,
12471250 context. config . max_width ( ) ,
12481251 shape,
0 commit comments