@@ -63,6 +63,7 @@ thread_local! {
63
63
static NO_TRIMMED_PATH : Cell <bool > = const { Cell :: new( false ) } ;
64
64
static NO_QUERIES : Cell <bool > = const { Cell :: new( false ) } ;
65
65
static NO_VISIBLE_PATH : Cell <bool > = const { Cell :: new( false ) } ;
66
+ static NO_VERBOSE_CONSTANTS : Cell <bool > = const { Cell :: new( false ) } ;
66
67
}
67
68
68
69
macro_rules! define_helper {
@@ -117,6 +118,9 @@ define_helper!(
117
118
/// Prevent selection of visible paths. `Display` impl of DefId will prefer
118
119
/// visible (public) reexports of types as paths.
119
120
fn with_no_visible_paths( NoVisibleGuard , NO_VISIBLE_PATH ) ;
121
+ /// Prevent verbose printing of constants. Verbose printing of constants is
122
+ /// never desirable in some contexts like `std::any::type_name`.
123
+ fn with_no_verbose_constants( NoVerboseConstantsGuard , NO_VERBOSE_CONSTANTS ) ;
120
124
) ;
121
125
122
126
/// The "region highlights" are used to control region printing during
@@ -759,7 +763,7 @@ pub trait PrettyPrinter<'tcx>:
759
763
}
760
764
ty:: Array ( ty, sz) => {
761
765
p ! ( "[" , print( ty) , "; " ) ;
762
- if self . tcx ( ) . sess . verbose ( ) {
766
+ if ! NO_VERBOSE_CONSTANTS . with ( |flag| flag . get ( ) ) && self . tcx ( ) . sess . verbose ( ) {
763
767
p ! ( write( "{:?}" , sz) ) ;
764
768
} else if let ty:: ConstKind :: Unevaluated ( ..) = sz. kind ( ) {
765
769
// Do not try to evaluate unevaluated constants. If we are const evaluating an
@@ -1181,7 +1185,7 @@ pub trait PrettyPrinter<'tcx>:
1181
1185
) -> Result < Self :: Const , Self :: Error > {
1182
1186
define_scoped_cx ! ( self ) ;
1183
1187
1184
- if self . tcx ( ) . sess . verbose ( ) {
1188
+ if ! NO_VERBOSE_CONSTANTS . with ( |flag| flag . get ( ) ) && self . tcx ( ) . sess . verbose ( ) {
1185
1189
p ! ( write( "Const({:?}: {:?})" , ct. kind( ) , ct. ty( ) ) ) ;
1186
1190
return Ok ( self ) ;
1187
1191
}
@@ -1416,7 +1420,7 @@ pub trait PrettyPrinter<'tcx>:
1416
1420
) -> Result < Self :: Const , Self :: Error > {
1417
1421
define_scoped_cx ! ( self ) ;
1418
1422
1419
- if self . tcx ( ) . sess . verbose ( ) {
1423
+ if ! NO_VERBOSE_CONSTANTS . with ( |flag| flag . get ( ) ) && self . tcx ( ) . sess . verbose ( ) {
1420
1424
p ! ( write( "ValTree({:?}: " , valtree) , print( ty) , ")" ) ;
1421
1425
return Ok ( self ) ;
1422
1426
}
0 commit comments