@@ -1697,6 +1697,25 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
16971697 } )
16981698 }
16991699
1700+ fn pretty_print_bound_constness (
1701+ & mut self ,
1702+ trait_ref : ty:: TraitRef < ' tcx > ,
1703+ ) -> Result < ( ) , PrintError > {
1704+ define_scoped_cx ! ( self ) ;
1705+
1706+ let Some ( idx) = self . tcx ( ) . generics_of ( trait_ref. def_id ) . host_effect_index else {
1707+ return Ok ( ( ) ) ;
1708+ } ;
1709+ let arg = trait_ref. args . const_at ( idx) ;
1710+
1711+ if arg == self . tcx ( ) . consts . false_ {
1712+ p ! ( "const " ) ;
1713+ } else if arg != self . tcx ( ) . consts . true_ && !arg. has_infer ( ) {
1714+ p ! ( "~const " ) ;
1715+ }
1716+ Ok ( ( ) )
1717+ }
1718+
17001719 fn should_print_verbose ( & self ) -> bool {
17011720 self . tcx ( ) . sess . verbose_internals ( )
17021721 }
@@ -2866,13 +2885,7 @@ define_print_and_forward_display! {
28662885 }
28672886
28682887 TraitPredPrintModifiersAndPath <' tcx> {
2869- if let Some ( idx) = cx. tcx( ) . generics_of( self . 0 . trait_ref. def_id) . host_effect_index
2870- {
2871- let arg = self . 0 . trait_ref. args. const_at( idx) ;
2872- if arg != cx. tcx( ) . consts. true_ && !arg. has_infer( ) {
2873- p!( "~const " ) ;
2874- }
2875- }
2888+ p!( pretty_print_bound_constness( self . 0 . trait_ref) ) ;
28762889 if let ty:: ImplPolarity :: Negative = self . 0 . polarity {
28772890 p!( "!" )
28782891 }
@@ -2905,11 +2918,7 @@ define_print_and_forward_display! {
29052918
29062919 ty:: TraitPredicate <' tcx> {
29072920 p!( print( self . trait_ref. self_ty( ) ) , ": " ) ;
2908- if let Some ( idx) = cx. tcx( ) . generics_of( self . trait_ref. def_id) . host_effect_index {
2909- if self . trait_ref. args. const_at( idx) != cx. tcx( ) . consts. true_ {
2910- p!( "~const " ) ;
2911- }
2912- }
2921+ p!( pretty_print_bound_constness( self . trait_ref) ) ;
29132922 if let ty:: ImplPolarity :: Negative = self . polarity {
29142923 p!( "!" ) ;
29152924 }
0 commit comments