@@ -2630,29 +2630,38 @@ fn rewrite_fn_base(
2630
2630
}
2631
2631
2632
2632
// Comment between return type and the end of the decl.
2633
- let snippet_lo = fd. output . span ( ) . hi ( ) ;
2634
2633
if where_clause. predicates . is_empty ( ) {
2634
+ let snippet_lo = fd. output . span ( ) . hi ( ) ;
2635
2635
let snippet_hi = span. hi ( ) ;
2636
- let snippet = context. snippet ( mk_sp ( snippet_lo, snippet_hi) ) ;
2637
- // Try to preserve the layout of the original snippet.
2638
- let original_starts_with_newline = snippet
2639
- . find ( |c| c != ' ' )
2640
- . map_or ( false , |i| starts_with_newline ( & snippet[ i..] ) ) ;
2641
- let original_ends_with_newline = snippet
2642
- . rfind ( |c| c != ' ' )
2643
- . map_or ( false , |i| snippet[ i..] . ends_with ( '\n' ) ) ;
2644
- let snippet = snippet. trim ( ) ;
2645
- if !snippet. is_empty ( ) {
2646
- result. push ( if original_starts_with_newline {
2647
- '\n'
2648
- } else {
2649
- ' '
2650
- } ) ;
2651
- result. push_str ( snippet) ;
2652
- if original_ends_with_newline {
2653
- force_new_line_for_brace = true ;
2636
+
2637
+ let mut deal_snippet = |snippet : & str | {
2638
+ // Try to preserve the layout of the original snippet.
2639
+ let original_starts_with_newline = snippet
2640
+ . find ( |c| c != ' ' )
2641
+ . map_or ( false , |i| starts_with_newline ( & snippet[ i..] ) ) ;
2642
+ let original_ends_with_newline = snippet
2643
+ . rfind ( |c| c != ' ' )
2644
+ . map_or ( false , |i| snippet[ i..] . ends_with ( '\n' ) ) ;
2645
+ let snippet = snippet. trim ( ) ;
2646
+ if !snippet. is_empty ( ) {
2647
+ result. push ( if original_starts_with_newline {
2648
+ '\n'
2649
+ } else {
2650
+ ' '
2651
+ } ) ;
2652
+ result. push_str ( snippet) ;
2653
+ if original_ends_with_newline {
2654
+ force_new_line_for_brace = true ;
2655
+ }
2654
2656
}
2655
- }
2657
+ } ;
2658
+
2659
+ if context. config . version ( ) == crate :: Version :: Two && where_clause. has_where_token {
2660
+ deal_snippet ( context. snippet ( mk_sp ( snippet_lo, where_clause. span . lo ( ) ) ) ) ;
2661
+ deal_snippet ( context. snippet ( mk_sp ( where_clause. span . hi ( ) , snippet_hi) ) ) ;
2662
+ } else {
2663
+ deal_snippet ( context. snippet ( mk_sp ( snippet_lo, snippet_hi) ) ) ;
2664
+ } ;
2656
2665
}
2657
2666
}
2658
2667
0 commit comments