@@ -13,7 +13,7 @@ use crate::comment::{
1313 rewrite_missing_comment, CharClasses , FindUncommented ,
1414} ;
1515use crate :: config:: lists:: * ;
16- use crate :: config:: { Config , ControlBraceStyle , IndentStyle , Version } ;
16+ use crate :: config:: { Config , ControlBraceStyle , HexLiteralCase , IndentStyle , Version } ;
1717use crate :: lists:: {
1818 definitive_tactic, itemize_list, shape_for_tactic, struct_lit_formatting, struct_lit_shape,
1919 struct_lit_tactic, write_list, ListFormatting , Separator ,
@@ -1168,6 +1168,7 @@ pub(crate) fn rewrite_literal(
11681168) -> Option < String > {
11691169 match l. kind {
11701170 ast:: LitKind :: Str ( _, ast:: StrStyle :: Cooked ) => rewrite_string_lit ( context, l. span , shape) ,
1171+ ast:: LitKind :: Int ( ..) => rewrite_int_lit ( context, l, shape) ,
11711172 _ => wrap_str (
11721173 context. snippet ( l. span ) . to_owned ( ) ,
11731174 context. config . max_width ( ) ,
@@ -1202,6 +1203,36 @@ fn rewrite_string_lit(context: &RewriteContext<'_>, span: Span, shape: Shape) ->
12021203 )
12031204}
12041205
1206+ fn rewrite_int_lit ( context : & RewriteContext < ' _ > , lit : & ast:: Lit , shape : Shape ) -> Option < String > {
1207+ let span = lit. span ;
1208+ let symbol = lit. token . symbol . as_str ( ) ;
1209+
1210+ if symbol. starts_with ( "0x" ) {
1211+ let hex_lit = match context. config . hex_literal_case ( ) {
1212+ HexLiteralCase :: Preserve => None ,
1213+ HexLiteralCase :: Upper => Some ( symbol[ 2 ..] . to_ascii_uppercase ( ) ) ,
1214+ HexLiteralCase :: Lower => Some ( symbol[ 2 ..] . to_ascii_lowercase ( ) ) ,
1215+ } ;
1216+ if let Some ( hex_lit) = hex_lit {
1217+ return wrap_str (
1218+ format ! (
1219+ "0x{}{}" ,
1220+ hex_lit,
1221+ lit. token. suffix. map_or( String :: new( ) , |s| s. to_string( ) )
1222+ ) ,
1223+ context. config . max_width ( ) ,
1224+ shape,
1225+ ) ;
1226+ }
1227+ }
1228+
1229+ wrap_str (
1230+ context. snippet ( span) . to_owned ( ) ,
1231+ context. config . max_width ( ) ,
1232+ shape,
1233+ )
1234+ }
1235+
12051236fn choose_separator_tactic ( context : & RewriteContext < ' _ > , span : Span ) -> Option < SeparatorTactic > {
12061237 if context. inside_macro ( ) {
12071238 if span_ends_with_comma ( context, span) {
0 commit comments