@@ -101,6 +101,9 @@ impl<'tcx> UseCratePrefixForSelfImports<'_, 'tcx> {
101101 fn in_same_block ( & self , cx : & LateContext < ' tcx > , span : Span ) -> bool {
102102 match self . latest_span {
103103 Some ( latest_span) => {
104+ if latest_span. contains ( span) {
105+ return true ;
106+ }
104107 let gap_span = latest_span. between ( span) ;
105108 let gap_snippet = gap_span. get_source_text ( cx) . unwrap ( ) ;
106109 for ( token, source, inner_span) in tokenize_with_text ( & gap_snippet) {
@@ -117,27 +120,18 @@ impl<'tcx> UseCratePrefixForSelfImports<'_, 'tcx> {
117120
118121 fn insert_item ( & mut self , cx : & LateContext < ' tcx > , item : & Item < ' tcx > ) {
119122 if self . in_same_block ( cx, item. span ) {
120- match item. kind {
121- ItemKind :: Mod ( ident, _) => {
122- self . mod_names . insert ( ident. name ) ;
123- } ,
124- ItemKind :: Use ( use_tree, _) => {
125- self . use_block . push ( use_tree) ;
126- } ,
127- _ => { } ,
128- }
129123 } else {
130124 self . try_lint ( cx) ;
131125 self . clear ( ) ;
132- match item . kind {
133- ItemKind :: Mod ( ident , _ ) => {
134- self . mod_names . insert ( ident. name ) ;
135- } ,
136- ItemKind :: Use ( use_tree , _ ) => {
137- self . use_block . push ( use_tree) ;
138- } ,
139- _ => { } ,
140- }
126+ }
127+ match item . kind {
128+ ItemKind :: Mod ( ident, _ ) => {
129+ self . mod_names . insert ( ident . name ) ;
130+ } ,
131+ ItemKind :: Use ( use_tree, _ ) => {
132+ self . use_block . push ( use_tree ) ;
133+ } ,
134+ _ => { } ,
141135 }
142136 self . latest_span = match self . latest_span {
143137 Some ( span) => Some ( span. with_hi ( item. span . hi ( ) ) ) ,
@@ -170,6 +164,6 @@ impl<'tcx> UseCratePrefixForSelfImports<'_, 'tcx> {
170164 fn clear ( & mut self ) {
171165 self . use_block . clear ( ) ;
172166 self . mod_names . clear ( ) ;
173- // self.spans.clear() ;
167+ self . latest_span = None ;
174168 }
175169}
0 commit comments