@@ -7,6 +7,21 @@ fn insert_at<T>(idx: usize, target: &mut Vec<T>, input: impl IntoIterator<Item =
77 target. splice ( idx..idx, input) ;
88}
99
10+ /// Recursively checks if a token tree contains any `HardNewLine`
11+ fn tokens_contain_hard_newline ( token : & AbstractLineToken < ' _ > ) -> bool {
12+ match token {
13+ AbstractLineToken :: ConcreteLineToken ( ConcreteLineToken :: HardNewLine ) => true ,
14+ AbstractLineToken :: BreakableEntry ( be) => {
15+ be. tokens ( ) . iter ( ) . any ( tokens_contain_hard_newline)
16+ }
17+ AbstractLineToken :: BreakableCallChainEntry ( bcce) => {
18+ bcce. tokens ( ) . iter ( ) . any ( tokens_contain_hard_newline)
19+ }
20+ AbstractLineToken :: ConditionalLayoutEntry ( cle) => cle. contains_hard_newline ( ) ,
21+ _ => false ,
22+ }
23+ }
24+
1025#[ derive( Copy , Clone , Debug ) ]
1126pub enum ConvertType {
1227 MultiLine ,
@@ -171,12 +186,7 @@ impl<'src> BreakableEntry<'src> {
171186 }
172187
173188 fn contains_hard_newline ( & self ) -> bool {
174- self . tokens . iter ( ) . any ( |t| {
175- matches ! (
176- t,
177- AbstractLineToken :: ConcreteLineToken ( ConcreteLineToken :: HardNewLine )
178- )
179- } )
189+ self . tokens . iter ( ) . any ( tokens_contain_hard_newline)
180190 }
181191
182192 pub fn single_line_len ( & self ) -> usize {
@@ -615,6 +625,16 @@ impl<'src> ConditionalLayoutEntry<'src> {
615625 || self . predicate_tokens . iter ( ) . any ( Self :: token_is_multiline)
616626 }
617627
628+ pub fn contains_hard_newline ( & self ) -> bool {
629+ self . statement_tokens
630+ . iter ( )
631+ . any ( tokens_contain_hard_newline)
632+ || self
633+ . predicate_tokens
634+ . iter ( )
635+ . any ( tokens_contain_hard_newline)
636+ }
637+
618638 fn token_is_multiline ( token : & AbstractLineToken < ' src > ) -> bool {
619639 match token {
620640 AbstractLineToken :: ConcreteLineToken ( ConcreteLineToken :: HardNewLine ) => true ,
0 commit comments