@@ -5,10 +5,10 @@ use def_id::LOCAL_CRATE;
55use rustc_data_structures:: fx:: FxHashSet ;
66use rustc_errors:: Applicability ;
77use rustc_hir:: def:: Res ;
8- use rustc_hir:: { Attribute , Item , ItemKind , UsePath , def_id} ;
8+ use rustc_hir:: { Item , ItemKind , UsePath , def_id} ;
99use rustc_lint:: { LateContext , LateLintPass , LintContext } ;
1010use rustc_session:: impl_lint_pass;
11- use rustc_span:: { BytePos , FileName , RealFileName , Span , Symbol , kw} ;
11+ use rustc_span:: { FileName , RealFileName , Span , Symbol , kw} ;
1212
1313declare_clippy_lint ! {
1414 /// ### What it does
@@ -83,21 +83,6 @@ impl<'a, 'tcx> LateLintPass<'tcx> for UseCratePrefixForSelfImports<'a, 'tcx> {
8383}
8484
8585impl < ' tcx > UseCratePrefixForSelfImports < ' _ , ' tcx > {
86- /*
87- fn in_same_block(&self, span: Span) -> bool {
88- if self.spans.is_empty() {
89- return true;
90- }
91- if self.spans.iter().any(|x| x.contains(span)) {
92- return true;
93- }
94- if self.spans.iter().any(|x| span.lo() - x.hi() == BytePos(1)) {
95- return true;
96- }
97- false
98- }
99- */
100-
10186 fn in_same_block ( & self , cx : & LateContext < ' tcx > , span : Span ) -> bool {
10287 match self . latest_span {
10388 Some ( latest_span) => {
@@ -106,15 +91,10 @@ impl<'tcx> UseCratePrefixForSelfImports<'_, 'tcx> {
10691 }
10792 let gap_span = latest_span. between ( span) ;
10893 let gap_snippet = gap_span. get_source_text ( cx) . unwrap ( ) ;
109- println ! ( "{:?}" , tokenize_with_text( & gap_snippet) . collect:: <Vec <_>>( ) ) ;
110- for ( token, source, inner_span) in tokenize_with_text ( & gap_snippet) {
111- match token {
112- rustc_lexer:: TokenKind :: Whitespace => {
113- if source. chars ( ) . filter ( |c| * c == '\n' ) . count ( ) > 1 {
114- return false ;
115- }
116- } ,
117- _ => { } ,
94+ for ( token, source, _) in tokenize_with_text ( & gap_snippet) {
95+ if token == rustc_lexer:: TokenKind :: Whitespace && source. chars ( ) . filter ( |c| * c == '\n' ) . count ( ) > 1
96+ {
97+ return false ;
11898 }
11999 }
120100 true
@@ -124,8 +104,10 @@ impl<'tcx> UseCratePrefixForSelfImports<'_, 'tcx> {
124104 }
125105
126106 fn insert_item ( & mut self , cx : & LateContext < ' tcx > , item : & Item < ' tcx > ) {
127- if self . in_same_block ( cx, item. span ) {
128- } else {
107+ if item. span . from_expansion ( ) {
108+ return ;
109+ }
110+ if !self . in_same_block ( cx, item. span ) {
129111 self . try_lint ( cx) ;
130112 self . clear ( ) ;
131113 }
@@ -139,7 +121,7 @@ impl<'tcx> UseCratePrefixForSelfImports<'_, 'tcx> {
139121 _ => { } ,
140122 }
141123 self . latest_span = match self . latest_span {
142- Some ( span ) => Some ( span . with_hi ( item. span . hi ( ) ) ) ,
124+ Some ( latest_span ) => Some ( latest_span . with_hi ( item. span . hi ( ) ) ) ,
143125 None => Some ( item. span ) ,
144126 } ;
145127 }
0 commit comments