@@ -613,26 +613,8 @@ impl Rewrite for ast::GenericBound {
613
613
ast:: GenericBound :: Trait ( ref poly_trait_ref) => {
614
614
let snippet = context. snippet ( self . span ( ) ) ;
615
615
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 ( ) ) ?;
633
616
poly_trait_ref
634
617
. rewrite_result ( context, shape)
635
- . map ( |s| format ! ( "{constness}{asyncness}{polarity}{s}" ) )
636
618
. map ( |s| if has_paren { format ! ( "({})" , s) } else { s } )
637
619
}
638
620
ast:: GenericBound :: Use ( ref args, span) => {
@@ -756,19 +738,41 @@ impl Rewrite for ast::PolyTraitRef {
756
738
}
757
739
758
740
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 )
760
743
{
761
744
// 6 is "for<> ".len()
762
745
let extra_offset = lifetime_str. len ( ) + 6 ;
763
746
let shape = shape
764
747
. offset_left ( extra_offset)
765
748
. 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)
769
750
} 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 ( ' ' ) ;
771
762
}
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
+ ) )
772
776
}
773
777
}
774
778
0 commit comments