@@ -3,13 +3,13 @@ use clippy_utils::source::{SpanRangeExt, snippet_indent};
33use clippy_utils:: tokenize_with_text;
44use itertools:: Itertools ;
55use rustc_ast:: token:: CommentKind ;
6- use rustc_ast:: { AttrKind , AttrStyle , Attribute , Crate , Item , ItemKind , ModKind , NodeId } ;
6+ use rustc_ast:: { AssocItemKind , AttrKind , AttrStyle , Attribute , Crate , Item , ItemKind , ModKind , NodeId } ;
77use rustc_errors:: { Applicability , Diag , SuggestionStyle } ;
88use rustc_lexer:: TokenKind ;
99use rustc_lint:: { EarlyContext , EarlyLintPass , LintContext } ;
1010use rustc_session:: impl_lint_pass;
1111use rustc_span:: symbol:: kw;
12- use rustc_span:: { BytePos , ExpnKind , InnerSpan , Span , SpanData , Symbol } ;
12+ use rustc_span:: { BytePos , ExpnKind , Ident , InnerSpan , Span , SpanData , Symbol } ;
1313
1414declare_clippy_lint ! {
1515 /// ### What it does
@@ -367,38 +367,26 @@ impl EmptyLineAfter {
367367 ) ;
368368 }
369369 }
370- }
371-
372- impl EarlyLintPass for EmptyLineAfter {
373- fn check_crate ( & mut self , _: & EarlyContext < ' _ > , krate : & Crate ) {
374- self . items . push ( ItemInfo {
375- kind : "crate" ,
376- name : kw:: Crate ,
377- span : krate. spans . inner_span . with_hi ( krate. spans . inner_span . lo ( ) ) ,
378- mod_items : krate
379- . items
380- . iter ( )
381- . filter ( |i| !matches ! ( i. span. ctxt( ) . outer_expn_data( ) . kind, ExpnKind :: AstPass ( _) ) )
382- . map ( |i| i. id )
383- . collect :: < Vec < _ > > ( ) ,
384- } ) ;
385- }
386-
387- fn check_item_post ( & mut self , _: & EarlyContext < ' _ > , _: & Item ) {
388- self . items . pop ( ) ;
389- }
390370
391- fn check_item ( & mut self , cx : & EarlyContext < ' _ > , item : & Item ) {
371+ fn check_item_kind (
372+ & mut self ,
373+ cx : & EarlyContext < ' _ > ,
374+ kind : & ItemKind ,
375+ ident : & Ident ,
376+ span : Span ,
377+ attrs : & [ Attribute ] ,
378+ id : NodeId ,
379+ ) {
392380 self . items . push ( ItemInfo {
393- kind : item . kind . descr ( ) ,
394- name : item . ident . name ,
395- span : if item . span . contains ( item . ident . span ) {
396- item . span . with_hi ( item . ident . span . hi ( ) )
381+ kind : kind. descr ( ) ,
382+ name : ident. name ,
383+ span : if span. contains ( ident. span ) {
384+ span. with_hi ( ident. span . hi ( ) )
397385 } else {
398- item . span . with_hi ( item . span . lo ( ) )
386+ span. with_hi ( span. lo ( ) )
399387 } ,
400- mod_items : match item . kind {
401- ItemKind :: Mod ( _, ModKind :: Loaded ( ref items, _, _, _) ) => items
388+ mod_items : match kind {
389+ ItemKind :: Mod ( _, ModKind :: Loaded ( items, _, _, _) ) => items
402390 . iter ( )
403391 . filter ( |i| !matches ! ( i. span. ctxt( ) . outer_expn_data( ) . kind, ExpnKind :: AstPass ( _) ) )
404392 . map ( |i| i. id )
@@ -407,8 +395,7 @@ impl EarlyLintPass for EmptyLineAfter {
407395 } ,
408396 } ) ;
409397
410- let mut outer = item
411- . attrs
398+ let mut outer = attrs
412399 . iter ( )
413400 . filter ( |attr| attr. style == AttrStyle :: Outer && !attr. span . from_expansion ( ) )
414401 . map ( |attr| Stop :: from_attr ( cx, attr) )
@@ -448,6 +435,52 @@ impl EarlyLintPass for EmptyLineAfter {
448435 }
449436 }
450437
451- self . check_gaps ( cx, & gaps, item. id ) ;
438+ self . check_gaps ( cx, & gaps, id) ;
439+ }
440+ }
441+
442+ impl EarlyLintPass for EmptyLineAfter {
443+ fn check_crate ( & mut self , _: & EarlyContext < ' _ > , krate : & Crate ) {
444+ self . items . push ( ItemInfo {
445+ kind : "crate" ,
446+ name : kw:: Crate ,
447+ span : krate. spans . inner_span . with_hi ( krate. spans . inner_span . lo ( ) ) ,
448+ mod_items : krate
449+ . items
450+ . iter ( )
451+ . filter ( |i| !matches ! ( i. span. ctxt( ) . outer_expn_data( ) . kind, ExpnKind :: AstPass ( _) ) )
452+ . map ( |i| i. id )
453+ . collect :: < Vec < _ > > ( ) ,
454+ } ) ;
455+ }
456+
457+ fn check_item_post ( & mut self , _: & EarlyContext < ' _ > , _: & Item ) {
458+ self . items . pop ( ) ;
459+ }
460+
461+ fn check_impl_item ( & mut self , cx : & EarlyContext < ' _ > , item : & Item < AssocItemKind > ) {
462+ self . check_item_kind (
463+ cx,
464+ & item. kind . clone ( ) . into ( ) ,
465+ & item. ident ,
466+ item. span ,
467+ & item. attrs ,
468+ item. id ,
469+ ) ;
470+ }
471+
472+ fn check_trait_item ( & mut self , cx : & EarlyContext < ' _ > , item : & Item < AssocItemKind > ) {
473+ self . check_item_kind (
474+ cx,
475+ & item. kind . clone ( ) . into ( ) ,
476+ & item. ident ,
477+ item. span ,
478+ & item. attrs ,
479+ item. id ,
480+ ) ;
481+ }
482+
483+ fn check_item ( & mut self , cx : & EarlyContext < ' _ > , item : & Item ) {
484+ self . check_item_kind ( cx, & item. kind , & item. ident , item. span , & item. attrs , item. id ) ;
452485 }
453486}
0 commit comments