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