@@ -2242,39 +2242,41 @@ impl<'tcx> Debug for Rvalue<'tcx> {
2242
2242
}
2243
2243
2244
2244
Aggregate ( ref kind, ref places) => {
2245
- fn fmt_tuple ( fmt : & mut Formatter < ' _ > , places : & [ Operand < ' _ > ] ) -> fmt :: Result {
2246
- let mut tuple_fmt = fmt. debug_tuple ( "" ) ;
2245
+ let fmt_tuple = | fmt : & mut Formatter < ' _ > , name : & str | {
2246
+ let mut tuple_fmt = fmt. debug_tuple ( name ) ;
2247
2247
for place in places {
2248
2248
tuple_fmt. field ( place) ;
2249
2249
}
2250
2250
tuple_fmt. finish ( )
2251
- }
2251
+ } ;
2252
2252
2253
2253
match * * kind {
2254
2254
AggregateKind :: Array ( _) => write ! ( fmt, "{:?}" , places) ,
2255
2255
2256
- AggregateKind :: Tuple => match places. len ( ) {
2257
- 0 => write ! ( fmt, "()" ) ,
2258
- 1 => write ! ( fmt, "({:?},)" , places[ 0 ] ) ,
2259
- _ => fmt_tuple ( fmt, places) ,
2260
- } ,
2256
+ AggregateKind :: Tuple => {
2257
+ if places. is_empty ( ) {
2258
+ write ! ( fmt, "()" )
2259
+ } else {
2260
+ fmt_tuple ( fmt, "" )
2261
+ }
2262
+ }
2261
2263
2262
2264
AggregateKind :: Adt ( adt_def, variant, substs, _user_ty, _) => {
2263
2265
let variant_def = & adt_def. variants [ variant] ;
2264
2266
2265
- let f = & mut * fmt ;
2266
- ty :: tls :: with ( |tcx| {
2267
+ let name = ty :: tls :: with ( |tcx| {
2268
+ let mut name = String :: new ( ) ;
2267
2269
let substs = tcx. lift ( & substs) . expect ( "could not lift for printing" ) ;
2268
- FmtPrinter :: new ( tcx, f , Namespace :: ValueNS )
2270
+ FmtPrinter :: new ( tcx, & mut name , Namespace :: ValueNS )
2269
2271
. print_def_path ( variant_def. def_id , substs) ?;
2270
- Ok ( ( ) )
2272
+ Ok ( name )
2271
2273
} ) ?;
2272
2274
2273
2275
match variant_def. ctor_kind {
2274
- CtorKind :: Const => Ok ( ( ) ) ,
2275
- CtorKind :: Fn => fmt_tuple ( fmt, places ) ,
2276
+ CtorKind :: Const => fmt . write_str ( & name ) ,
2277
+ CtorKind :: Fn => fmt_tuple ( fmt, & name ) ,
2276
2278
CtorKind :: Fictive => {
2277
- let mut struct_fmt = fmt. debug_struct ( "" ) ;
2279
+ let mut struct_fmt = fmt. debug_struct ( & name ) ;
2278
2280
for ( field, place) in variant_def. fields . iter ( ) . zip ( places) {
2279
2281
struct_fmt. field ( & field. ident . as_str ( ) , place) ;
2280
2282
}
0 commit comments