@@ -2386,31 +2386,32 @@ pub fn rendered_const<'tcx>(tcx: TyCtxt<'tcx>, body: hir::BodyId) -> String {
2386
2386
}
2387
2387
}
2388
2388
2389
- let classification = classify ( value) ;
2390
-
2391
- if classification == Literal
2392
- && !value. span . from_expansion ( )
2393
- && let Ok ( snippet) = tcx. sess . source_map ( ) . span_to_snippet ( value. span )
2394
- {
2395
- // For literals, we avoid invoking the pretty-printer and use the source snippet instead to
2396
- // preserve certain stylistic choices the user likely made for the sake legibility like
2389
+ match classify ( value) {
2390
+ // For non-macro literals, we avoid invoking the pretty-printer and use the source snippet
2391
+ // instead to preserve certain stylistic choices the user likely made for the sake of
2392
+ // legibility, like:
2397
2393
//
2398
2394
// * hexadecimal notation
2399
2395
// * underscores
2400
2396
// * character escapes
2401
2397
//
2402
2398
// FIXME: This passes through `-/*spacer*/0` verbatim.
2403
- snippet
2404
- } else if classification == Simple {
2399
+ Literal if !value. span . from_expansion ( )
2400
+ && let Ok ( snippet) = tcx. sess . source_map ( ) . span_to_snippet ( value. span ) => {
2401
+ snippet
2402
+ }
2403
+
2405
2404
// Otherwise we prefer pretty-printing to get rid of extraneous whitespace, comments and
2406
2405
// other formatting artifacts.
2407
- id_to_string ( & hir, body. hir_id )
2408
- } else if tcx . def_kind ( hir . body_owner_def_id ( body ) . to_def_id ( ) ) == DefKind :: AnonConst {
2406
+ Literal | Simple => id_to_string ( & hir, body. hir_id ) ,
2407
+
2409
2408
// FIXME: Omit the curly braces if the enclosing expression is an array literal
2410
2409
// with a repeated element (an `ExprKind::Repeat`) as in such case it
2411
2410
// would not actually need any disambiguation.
2412
- "{ _ }" . to_owned ( )
2413
- } else {
2414
- "_" . to_owned ( )
2411
+ Complex => if tcx. def_kind ( hir. body_owner_def_id ( body) . to_def_id ( ) ) == DefKind :: AnonConst {
2412
+ "{ _ }" . to_owned ( )
2413
+ } else {
2414
+ "_" . to_owned ( )
2415
+ }
2415
2416
}
2416
2417
}
0 commit comments