@@ -17,7 +17,7 @@ use rustc_middle::mir::interpret::{
17
17
} ;
18
18
use rustc_middle:: mir:: visit:: Visitor ;
19
19
use rustc_middle:: mir:: * ;
20
- use rustc_middle:: ty:: { self , TyCtxt , TypeFoldable , TypeVisitor } ;
20
+ use rustc_middle:: ty:: { self , TyCtxt , TyS , TypeFoldable , TypeVisitor } ;
21
21
use rustc_target:: abi:: Size ;
22
22
use std:: ops:: ControlFlow ;
23
23
@@ -408,6 +408,18 @@ impl ExtraComments<'tcx> {
408
408
}
409
409
}
410
410
411
+ fn use_verbose ( ty : & & TyS < ' tcx > ) -> bool {
412
+ match ty. kind ( ) {
413
+ ty:: Int ( _) | ty:: Uint ( _) | ty:: Bool | ty:: Char | ty:: Float ( _) => false ,
414
+ // Unit type
415
+ ty:: Tuple ( g_args) if g_args. is_empty ( ) => false ,
416
+ ty:: Tuple ( g_args) => g_args. iter ( ) . any ( |g_arg| use_verbose ( & g_arg. expect_ty ( ) ) ) ,
417
+ ty:: Array ( ty, _) => use_verbose ( ty) ,
418
+ ty:: FnDef ( ..) => false ,
419
+ _ => true ,
420
+ }
421
+ }
422
+
411
423
impl Visitor < ' tcx > for ExtraComments < ' tcx > {
412
424
fn visit_constant ( & mut self , constant : & Constant < ' tcx > , location : Location ) {
413
425
self . super_constant ( constant, location) ;
@@ -430,16 +442,10 @@ impl Visitor<'tcx> for ExtraComments<'tcx> {
430
442
fn visit_const ( & mut self , constant : & & ' tcx ty:: Const < ' tcx > , _: Location ) {
431
443
self . super_const ( constant) ;
432
444
let ty:: Const { ty, val, .. } = constant;
433
- match ty. kind ( ) {
434
- ty:: Int ( _) | ty:: Uint ( _) | ty:: Bool | ty:: Char | ty:: Float ( _) => { }
435
- // Unit type
436
- ty:: Tuple ( tys) if tys. is_empty ( ) => { }
437
- ty:: FnDef ( ..) => { }
438
- _ => {
439
- self . push ( "ty::Const" ) ;
440
- self . push ( & format ! ( "+ ty: {:?}" , ty) ) ;
441
- self . push ( & format ! ( "+ val: {:?}" , val) ) ;
442
- }
445
+ if use_verbose ( ty) {
446
+ self . push ( "ty::Const" ) ;
447
+ self . push ( & format ! ( "+ ty: {:?}" , ty) ) ;
448
+ self . push ( & format ! ( "+ val: {:?}" , val) ) ;
443
449
}
444
450
}
445
451
0 commit comments