@@ -63,6 +63,7 @@ thread_local! {
6363 static NO_TRIMMED_PATH : Cell <bool > = const { Cell :: new( false ) } ;
6464 static NO_QUERIES : Cell <bool > = const { Cell :: new( false ) } ;
6565 static NO_VISIBLE_PATH : Cell <bool > = const { Cell :: new( false ) } ;
66+ static NO_VERBOSE_CONSTANTS : Cell <bool > = const { Cell :: new( false ) } ;
6667}
6768
6869macro_rules! define_helper {
@@ -117,6 +118,9 @@ define_helper!(
117118 /// Prevent selection of visible paths. `Display` impl of DefId will prefer
118119 /// visible (public) reexports of types as paths.
119120 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 ) ;
120124) ;
121125
122126/// The "region highlights" are used to control region printing during
@@ -759,7 +763,7 @@ pub trait PrettyPrinter<'tcx>:
759763 }
760764 ty:: Array ( ty, sz) => {
761765 p ! ( "[" , print( ty) , "; " ) ;
762- if self . tcx ( ) . sess . verbose ( ) {
766+ if ! NO_VERBOSE_CONSTANTS . with ( |flag| flag . get ( ) ) && self . tcx ( ) . sess . verbose ( ) {
763767 p ! ( write( "{:?}" , sz) ) ;
764768 } else if let ty:: ConstKind :: Unevaluated ( ..) = sz. kind ( ) {
765769 // Do not try to evaluate unevaluated constants. If we are const evaluating an
@@ -1181,7 +1185,7 @@ pub trait PrettyPrinter<'tcx>:
11811185 ) -> Result < Self :: Const , Self :: Error > {
11821186 define_scoped_cx ! ( self ) ;
11831187
1184- if self . tcx ( ) . sess . verbose ( ) {
1188+ if ! NO_VERBOSE_CONSTANTS . with ( |flag| flag . get ( ) ) && self . tcx ( ) . sess . verbose ( ) {
11851189 p ! ( write( "Const({:?}: {:?})" , ct. kind( ) , ct. ty( ) ) ) ;
11861190 return Ok ( self ) ;
11871191 }
@@ -1416,7 +1420,7 @@ pub trait PrettyPrinter<'tcx>:
14161420 ) -> Result < Self :: Const , Self :: Error > {
14171421 define_scoped_cx ! ( self ) ;
14181422
1419- if self . tcx ( ) . sess . verbose ( ) {
1423+ if ! NO_VERBOSE_CONSTANTS . with ( |flag| flag . get ( ) ) && self . tcx ( ) . sess . verbose ( ) {
14201424 p ! ( write( "ValTree({:?}: " , valtree) , print( ty) , ")" ) ;
14211425 return Ok ( self ) ;
14221426 }
0 commit comments