@@ -275,7 +275,8 @@ pub(crate) fn print_const(cx: &DocContext<'_>, n: ty::Const<'_>) -> String {
275275pub ( crate ) fn print_evaluated_const (
276276 tcx : TyCtxt < ' _ > ,
277277 def_id : DefId ,
278- underscores_and_type : bool ,
278+ with_underscores : bool ,
279+ with_type : bool ,
279280) -> Option < String > {
280281 tcx. const_eval_poly ( def_id) . ok ( ) . and_then ( |val| {
281282 let ty = tcx. type_of ( def_id) . instantiate_identity ( ) ;
@@ -284,7 +285,7 @@ pub(crate) fn print_evaluated_const(
284285 ( mir:: ConstValue :: Scalar ( _) , & ty:: Adt ( _, _) ) => None ,
285286 ( mir:: ConstValue :: Scalar ( _) , _) => {
286287 let const_ = mir:: Const :: from_value ( val, ty) ;
287- Some ( print_const_with_custom_print_scalar ( tcx, const_, underscores_and_type ) )
288+ Some ( print_const_with_custom_print_scalar ( tcx, const_, with_underscores , with_type ) )
288289 }
289290 _ => None ,
290291 }
@@ -320,14 +321,25 @@ fn format_integer_with_underscore_sep(num: &str) -> String {
320321fn print_const_with_custom_print_scalar < ' tcx > (
321322 tcx : TyCtxt < ' tcx > ,
322323 ct : mir:: Const < ' tcx > ,
323- underscores_and_type : bool ,
324+ with_underscores : bool ,
325+ with_type : bool ,
324326) -> String {
325327 // Use a slightly different format for integer types which always shows the actual value.
326328 // For all other types, fallback to the original `pretty_print_const`.
327329 match ( ct, ct. ty ( ) . kind ( ) ) {
328330 ( mir:: Const :: Val ( mir:: ConstValue :: Scalar ( int) , _) , ty:: Uint ( ui) ) => {
329- if underscores_and_type {
330- format ! ( "{}{}" , format_integer_with_underscore_sep( & int. to_string( ) ) , ui. name_str( ) )
331+ if with_underscores {
332+ if with_type {
333+ format ! (
334+ "{}{}" ,
335+ format_integer_with_underscore_sep( & int. to_string( ) ) ,
336+ ui. name_str( )
337+ )
338+ } else {
339+ format_integer_with_underscore_sep ( & int. to_string ( ) )
340+ }
341+ } else if with_type {
342+ format ! ( "{}{}" , int. to_string( ) , ui. name_str( ) )
331343 } else {
332344 int. to_string ( )
333345 }
@@ -337,12 +349,18 @@ fn print_const_with_custom_print_scalar<'tcx>(
337349 let size = tcx. layout_of ( ty:: ParamEnv :: empty ( ) . and ( ty) ) . unwrap ( ) . size ;
338350 let data = int. assert_bits ( size) ;
339351 let sign_extended_data = size. sign_extend ( data) as i128 ;
340- if underscores_and_type {
341- format ! (
342- "{}{}" ,
343- format_integer_with_underscore_sep( & sign_extended_data. to_string( ) ) ,
344- i. name_str( )
345- )
352+ if with_underscores {
353+ if with_type {
354+ format ! (
355+ "{}{}" ,
356+ format_integer_with_underscore_sep( & sign_extended_data. to_string( ) ) ,
357+ i. name_str( )
358+ )
359+ } else {
360+ format_integer_with_underscore_sep ( & sign_extended_data. to_string ( ) )
361+ }
362+ } else if with_type {
363+ format ! ( "{}{}" , sign_extended_data. to_string( ) , i. name_str( ) )
346364 } else {
347365 sign_extended_data. to_string ( )
348366 }
0 commit comments