@@ -17,7 +17,8 @@ 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:: subst:: GenericArgKind ;
21
+ use rustc_middle:: ty:: { self , TyCtxt , TyS , TypeFoldable , TypeVisitor } ;
21
22
use rustc_target:: abi:: Size ;
22
23
use std:: ops:: ControlFlow ;
23
24
@@ -408,6 +409,33 @@ impl ExtraComments<'tcx> {
408
409
}
409
410
}
410
411
412
+ fn use_verbose ( ty : & & TyS < ' tcx > ) -> bool {
413
+ match ty. kind ( ) {
414
+ ty:: Int ( _) | ty:: Uint ( _) | ty:: Bool | ty:: Char | ty:: Float ( _) => false ,
415
+ // Unit type
416
+ ty:: Tuple ( g_args) if g_args. is_empty ( ) => false ,
417
+ ty:: Tuple ( g_args) => {
418
+ // could have used `try_fold` here but it seems a bit silly that
419
+ // the accumulator is useless
420
+ let mut should_be_verbose = false ;
421
+ for g_arg in g_args. iter ( ) {
422
+ if match g_arg. unpack ( ) {
423
+ GenericArgKind :: Type ( ty) => use_verbose ( & ty) ,
424
+ GenericArgKind :: Const ( ty:: Const { ty, val : _ } ) => use_verbose ( ty) ,
425
+ _ => false ,
426
+ } {
427
+ should_be_verbose = true ;
428
+ break ;
429
+ }
430
+ }
431
+ should_be_verbose
432
+ }
433
+ ty:: Array ( ty, _) => use_verbose ( ty) ,
434
+ ty:: FnDef ( ..) => false ,
435
+ _ => true ,
436
+ }
437
+ }
438
+
411
439
impl Visitor < ' tcx > for ExtraComments < ' tcx > {
412
440
fn visit_constant ( & mut self , constant : & Constant < ' tcx > , location : Location ) {
413
441
self . super_constant ( constant, location) ;
@@ -430,16 +458,10 @@ impl Visitor<'tcx> for ExtraComments<'tcx> {
430
458
fn visit_const ( & mut self , constant : & & ' tcx ty:: Const < ' tcx > , _: Location ) {
431
459
self . super_const ( constant) ;
432
460
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
- }
461
+ if use_verbose ( ty) {
462
+ self . push ( "ty::Const" ) ;
463
+ self . push ( & format ! ( "+ ty: {:?}" , ty) ) ;
464
+ self . push ( & format ! ( "+ val: {:?}" , val) ) ;
443
465
}
444
466
}
445
467
0 commit comments