@@ -181,6 +181,14 @@ impl UseSegment {
181181 }
182182 } )
183183 }
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+ }
184192}
185193
186194pub ( crate ) fn normalize_use_trees_with_granularity (
@@ -197,7 +205,7 @@ pub(crate) fn normalize_use_trees_with_granularity(
197205
198206 let mut result = Vec :: with_capacity ( use_trees. len ( ) ) ;
199207 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 ( ) {
201209 result. push ( use_tree) ;
202210 continue ;
203211 }
@@ -556,6 +564,10 @@ impl UseTree {
556564 self . list_item . as_ref ( ) . map_or ( false , ListItem :: has_comment)
557565 }
558566
567+ fn contains_comment ( & self ) -> bool {
568+ self . has_comment ( ) || self . path . iter ( ) . any ( |path| path. contains_comment ( ) )
569+ }
570+
559571 fn same_visibility ( & self , other : & UseTree ) -> bool {
560572 match ( & self . visibility , & other. visibility ) {
561573 (
@@ -582,6 +594,7 @@ impl UseTree {
582594 if self . path . is_empty ( )
583595 || other. path . is_empty ( )
584596 || self . attrs . is_some ( )
597+ || self . contains_comment ( )
585598 || !self . same_visibility ( other)
586599 {
587600 false
@@ -597,7 +610,7 @@ impl UseTree {
597610 }
598611
599612 fn flatten ( self , import_granularity : ImportGranularity ) -> Vec < UseTree > {
600- if self . path . is_empty ( ) {
613+ if self . path . is_empty ( ) || self . contains_comment ( ) {
601614 return vec ! [ self ] ;
602615 }
603616 match self . path . clone ( ) . last ( ) . unwrap ( ) {
0 commit comments