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