@@ -181,6 +181,14 @@ impl UseSegment {
181
181
}
182
182
} )
183
183
}
184
+
185
+ fn contains_comment ( & self ) -> bool {
186
+ if let UseSegment :: List ( list) = self {
187
+ list. iter ( ) . any ( |subtree| subtree. contains_comment ( ) )
188
+ } else {
189
+ false
190
+ }
191
+ }
184
192
}
185
193
186
194
pub ( crate ) fn normalize_use_trees_with_granularity (
@@ -197,7 +205,7 @@ pub(crate) fn normalize_use_trees_with_granularity(
197
205
198
206
let mut result = Vec :: with_capacity ( use_trees. len ( ) ) ;
199
207
for use_tree in use_trees {
200
- if use_tree. has_comment ( ) || use_tree. attrs . is_some ( ) {
208
+ if use_tree. contains_comment ( ) || use_tree. attrs . is_some ( ) {
201
209
result. push ( use_tree) ;
202
210
continue ;
203
211
}
@@ -556,6 +564,10 @@ impl UseTree {
556
564
self . list_item . as_ref ( ) . map_or ( false , ListItem :: has_comment)
557
565
}
558
566
567
+ fn contains_comment ( & self ) -> bool {
568
+ self . has_comment ( ) || self . path . iter ( ) . any ( |path| path. contains_comment ( ) )
569
+ }
570
+
559
571
fn same_visibility ( & self , other : & UseTree ) -> bool {
560
572
match ( & self . visibility , & other. visibility ) {
561
573
(
@@ -582,6 +594,7 @@ impl UseTree {
582
594
if self . path . is_empty ( )
583
595
|| other. path . is_empty ( )
584
596
|| self . attrs . is_some ( )
597
+ || self . contains_comment ( )
585
598
|| !self . same_visibility ( other)
586
599
{
587
600
false
@@ -597,7 +610,7 @@ impl UseTree {
597
610
}
598
611
599
612
fn flatten ( self , import_granularity : ImportGranularity ) -> Vec < UseTree > {
600
- if self . path . is_empty ( ) {
613
+ if self . path . is_empty ( ) || self . contains_comment ( ) {
601
614
return vec ! [ self ] ;
602
615
}
603
616
match self . path . clone ( ) . last ( ) . unwrap ( ) {
0 commit comments