@@ -613,26 +613,8 @@ impl Rewrite for ast::GenericBound {
613613 ast:: GenericBound :: Trait ( ref poly_trait_ref) => {
614614 let snippet = context. snippet ( self . span ( ) ) ;
615615 let has_paren = snippet. starts_with ( '(' ) && snippet. ends_with ( ')' ) ;
616- let ast:: TraitBoundModifiers {
617- constness,
618- asyncness,
619- polarity,
620- } = poly_trait_ref. modifiers ;
621- let mut constness = constness. as_str ( ) . to_string ( ) ;
622- if !constness. is_empty ( ) {
623- constness. push ( ' ' ) ;
624- }
625- let mut asyncness = asyncness. as_str ( ) . to_string ( ) ;
626- if !asyncness. is_empty ( ) {
627- asyncness. push ( ' ' ) ;
628- }
629- let polarity = polarity. as_str ( ) ;
630- let shape = shape
631- . offset_left ( constness. len ( ) + polarity. len ( ) )
632- . max_width_error ( shape. width , self . span ( ) ) ?;
633616 poly_trait_ref
634617 . rewrite_result ( context, shape)
635- . map ( |s| format ! ( "{constness}{asyncness}{polarity}{s}" ) )
636618 . map ( |s| if has_paren { format ! ( "({})" , s) } else { s } )
637619 }
638620 ast:: GenericBound :: Use ( ref args, span) => {
@@ -756,19 +738,41 @@ impl Rewrite for ast::PolyTraitRef {
756738 }
757739
758740 fn rewrite_result ( & self , context : & RewriteContext < ' _ > , shape : Shape ) -> RewriteResult {
759- if let Some ( lifetime_str) = rewrite_bound_params ( context, shape, & self . bound_generic_params )
741+ let ( binder, shape) = if let Some ( lifetime_str) =
742+ rewrite_bound_params ( context, shape, & self . bound_generic_params )
760743 {
761744 // 6 is "for<> ".len()
762745 let extra_offset = lifetime_str. len ( ) + 6 ;
763746 let shape = shape
764747 . offset_left ( extra_offset)
765748 . max_width_error ( shape. width , self . span ) ?;
766- let path_str = self . trait_ref . rewrite_result ( context, shape) ?;
767-
768- Ok ( format ! ( "for<{lifetime_str}> {path_str}" ) )
749+ ( format ! ( "for<{lifetime_str}> " ) , shape)
769750 } else {
770- self . trait_ref . rewrite_result ( context, shape)
751+ ( String :: new ( ) , shape)
752+ } ;
753+
754+ let ast:: TraitBoundModifiers {
755+ constness,
756+ asyncness,
757+ polarity,
758+ } = self . modifiers ;
759+ let mut constness = constness. as_str ( ) . to_string ( ) ;
760+ if !constness. is_empty ( ) {
761+ constness. push ( ' ' ) ;
771762 }
763+ let mut asyncness = asyncness. as_str ( ) . to_string ( ) ;
764+ if !asyncness. is_empty ( ) {
765+ asyncness. push ( ' ' ) ;
766+ }
767+ let polarity = polarity. as_str ( ) ;
768+ let shape = shape
769+ . offset_left ( constness. len ( ) + polarity. len ( ) )
770+ . max_width_error ( shape. width , self . span ) ?;
771+
772+ let path_str = self . trait_ref . rewrite_result ( context, shape) ?;
773+ Ok ( format ! (
774+ "{binder}{constness}{asyncness}{polarity}{path_str}"
775+ ) )
772776 }
773777}
774778
0 commit comments