@@ -13,7 +13,7 @@ use crate::comment::{
13
13
rewrite_missing_comment, CharClasses , FindUncommented ,
14
14
} ;
15
15
use crate :: config:: lists:: * ;
16
- use crate :: config:: { Config , ControlBraceStyle , IndentStyle , Version } ;
16
+ use crate :: config:: { Config , ControlBraceStyle , HexLiteralCase , IndentStyle , Version } ;
17
17
use crate :: lists:: {
18
18
definitive_tactic, itemize_list, shape_for_tactic, struct_lit_formatting, struct_lit_shape,
19
19
struct_lit_tactic, write_list, ListFormatting , Separator ,
@@ -1168,6 +1168,7 @@ pub(crate) fn rewrite_literal(
1168
1168
) -> Option < String > {
1169
1169
match l. kind {
1170
1170
ast:: LitKind :: Str ( _, ast:: StrStyle :: Cooked ) => rewrite_string_lit ( context, l. span , shape) ,
1171
+ ast:: LitKind :: Int ( ..) => rewrite_int_lit ( context, l, shape) ,
1171
1172
_ => wrap_str (
1172
1173
context. snippet ( l. span ) . to_owned ( ) ,
1173
1174
context. config . max_width ( ) ,
@@ -1202,6 +1203,36 @@ fn rewrite_string_lit(context: &RewriteContext<'_>, span: Span, shape: Shape) ->
1202
1203
)
1203
1204
}
1204
1205
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
+
1205
1236
fn choose_separator_tactic ( context : & RewriteContext < ' _ > , span : Span ) -> Option < SeparatorTactic > {
1206
1237
if context. inside_macro ( ) {
1207
1238
if span_ends_with_comma ( context, span) {
0 commit comments