@@ -80,7 +80,6 @@ use utils::{
80
80
81
81
use std:: borrow:: Cow ;
82
82
use std:: cmp:: min;
83
- use std:: iter;
84
83
85
84
use syntax:: source_map:: { BytePos , Span } ;
86
85
use syntax:: { ast, ptr} ;
@@ -132,8 +131,8 @@ impl ChainItemKind {
132
131
fn is_block_like ( & self , context : & RewriteContext , reps : & str ) -> bool {
133
132
match self {
134
133
ChainItemKind :: Parent ( ref expr) => is_block_expr ( context, expr, reps) ,
135
- ChainItemKind :: MethodCall ( ..) => reps . contains ( '\n' ) ,
136
- ChainItemKind :: StructField ( ..)
134
+ ChainItemKind :: MethodCall ( ..)
135
+ | ChainItemKind :: StructField ( ..)
137
136
| ChainItemKind :: TupleField ( ..)
138
137
| ChainItemKind :: Comment ( ..) => false ,
139
138
}
@@ -625,12 +624,7 @@ impl<'a> ChainFormatterShared<'a> {
625
624
Some ( ( ) )
626
625
}
627
626
628
- fn join_rewrites (
629
- & self ,
630
- context : & RewriteContext ,
631
- child_shape : Shape ,
632
- block_like_iter : impl Iterator < Item = bool > ,
633
- ) -> Option < String > {
627
+ fn join_rewrites ( & self , context : & RewriteContext , child_shape : Shape ) -> Option < String > {
634
628
let connector = if self . fits_single_line {
635
629
// Yay, we can put everything on one line.
636
630
Cow :: from ( "" )
@@ -645,17 +639,13 @@ impl<'a> ChainFormatterShared<'a> {
645
639
let mut rewrite_iter = self . rewrites . iter ( ) ;
646
640
let mut result = rewrite_iter. next ( ) . unwrap ( ) . clone ( ) ;
647
641
let children_iter = self . children . iter ( ) ;
648
- let iter = rewrite_iter. zip ( block_like_iter ) . zip ( children_iter) ;
642
+ let iter = rewrite_iter. zip ( children_iter) ;
649
643
650
- for ( ( rewrite, prev_is_block_like ) , chain_item) in iter {
644
+ for ( rewrite, chain_item) in iter {
651
645
match chain_item. kind {
652
646
ChainItemKind :: Comment ( _, CommentPosition :: Back ) => result. push ( ' ' ) ,
653
647
ChainItemKind :: Comment ( _, CommentPosition :: Top ) => result. push_str ( & connector) ,
654
- _ => {
655
- if !prev_is_block_like {
656
- result. push_str ( & connector) ;
657
- }
658
- }
648
+ _ => result. push_str ( & connector) ,
659
649
}
660
650
result. push_str ( & rewrite) ;
661
651
}
@@ -667,15 +657,14 @@ impl<'a> ChainFormatterShared<'a> {
667
657
// Formats a chain using block indent.
668
658
struct ChainFormatterBlock < ' a > {
669
659
shared : ChainFormatterShared < ' a > ,
670
- // For each rewrite, whether the corresponding item is block-like.
671
- is_block_like : Vec < bool > ,
660
+ root_ends_with_block : bool ,
672
661
}
673
662
674
663
impl < ' a > ChainFormatterBlock < ' a > {
675
664
fn new ( chain : & ' a Chain ) -> ChainFormatterBlock < ' a > {
676
665
ChainFormatterBlock {
677
666
shared : ChainFormatterShared :: new ( chain) ,
678
- is_block_like : Vec :: with_capacity ( chain . children . len ( ) + 1 ) ,
667
+ root_ends_with_block : false ,
679
668
}
680
669
}
681
670
}
@@ -703,21 +692,21 @@ impl<'a> ChainFormatter for ChainFormatterBlock<'a> {
703
692
None => break ,
704
693
}
705
694
706
- root_ends_with_block = item . kind . is_block_like ( context , & root_rewrite) ;
695
+ root_ends_with_block = last_line_extendable ( & root_rewrite) ;
707
696
708
697
self . shared . children = & self . shared . children [ 1 ..] ;
709
698
if self . shared . children . is_empty ( ) {
710
699
break ;
711
700
}
712
701
}
713
- self . is_block_like . push ( root_ends_with_block) ;
714
702
self . shared . rewrites . push ( root_rewrite) ;
703
+ self . root_ends_with_block = root_ends_with_block;
715
704
Some ( ( ) )
716
705
}
717
706
718
707
fn child_shape ( & self , context : & RewriteContext , shape : Shape ) -> Option < Shape > {
719
708
Some (
720
- if self . is_block_like [ 0 ] {
709
+ if self . root_ends_with_block {
721
710
shape. block_indent ( 0 )
722
711
} else {
723
712
shape. block_indent ( context. config . tab_spaces ( ) )
@@ -728,8 +717,6 @@ impl<'a> ChainFormatter for ChainFormatterBlock<'a> {
728
717
fn format_children ( & mut self , context : & RewriteContext , child_shape : Shape ) -> Option < ( ) > {
729
718
for item in & self . shared . children [ ..self . shared . children . len ( ) - 1 ] {
730
719
let rewrite = item. rewrite ( context, child_shape) ?;
731
- self . is_block_like
732
- . push ( item. kind . is_block_like ( context, & rewrite) ) ;
733
720
self . shared . rewrites . push ( rewrite) ;
734
721
}
735
722
Some ( ( ) )
@@ -746,8 +733,7 @@ impl<'a> ChainFormatter for ChainFormatterBlock<'a> {
746
733
}
747
734
748
735
fn join_rewrites ( & self , context : & RewriteContext , child_shape : Shape ) -> Option < String > {
749
- self . shared
750
- . join_rewrites ( context, child_shape, self . is_block_like . iter ( ) . cloned ( ) )
736
+ self . shared . join_rewrites ( context, child_shape)
751
737
}
752
738
753
739
fn pure_root ( & mut self ) -> Option < String > {
@@ -841,8 +827,7 @@ impl<'a> ChainFormatter for ChainFormatterVisual<'a> {
841
827
}
842
828
843
829
fn join_rewrites ( & self , context : & RewriteContext , child_shape : Shape ) -> Option < String > {
844
- self . shared
845
- . join_rewrites ( context, child_shape, iter:: repeat ( false ) )
830
+ self . shared . join_rewrites ( context, child_shape)
846
831
}
847
832
848
833
fn pure_root ( & mut self ) -> Option < String > {
0 commit comments