@@ -248,7 +248,6 @@ declare_lint_pass!(Attributes => [
248248 INLINE_ALWAYS ,
249249 DEPRECATED_SEMVER ,
250250 USELESS_ATTRIBUTE ,
251- EMPTY_LINE_AFTER_OUTER_ATTR ,
252251 UNKNOWN_CLIPPY_LINTS ,
253252] ) ;
254253
@@ -480,36 +479,6 @@ fn check_attrs(cx: &LateContext<'_, '_>, span: Span, name: Name, attrs: &[Attrib
480479 }
481480
482481 for attr in attrs {
483- let attr_item = if let AttrKind :: Normal ( ref attr) = attr. kind {
484- attr
485- } else {
486- continue ;
487- } ;
488-
489- if attr. style == AttrStyle :: Outer {
490- if attr_item. args . inner_tokens ( ) . is_empty ( ) || !is_present_in_source ( cx, attr. span ) {
491- return ;
492- }
493-
494- let begin_of_attr_to_item = Span :: new ( attr. span . lo ( ) , span. lo ( ) , span. ctxt ( ) ) ;
495- let end_of_attr_to_item = Span :: new ( attr. span . hi ( ) , span. lo ( ) , span. ctxt ( ) ) ;
496-
497- if let Some ( snippet) = snippet_opt ( cx, end_of_attr_to_item) {
498- let lines = snippet. split ( '\n' ) . collect :: < Vec < _ > > ( ) ;
499- let lines = without_block_comments ( lines) ;
500-
501- if lines. iter ( ) . filter ( |l| l. trim ( ) . is_empty ( ) ) . count ( ) > 2 {
502- span_lint (
503- cx,
504- EMPTY_LINE_AFTER_OUTER_ATTR ,
505- begin_of_attr_to_item,
506- "Found an empty line after an outer attribute. \
507- Perhaps you forgot to add a `!` to make it an inner attribute?",
508- ) ;
509- }
510- }
511- }
512-
513482 if let Some ( values) = attr. meta_item_list ( ) {
514483 if values. len ( ) != 1 || !attr. check_name ( sym ! ( inline) ) {
515484 continue ;
@@ -551,15 +520,57 @@ fn is_word(nmi: &NestedMetaItem, expected: Symbol) -> bool {
551520 }
552521}
553522
554- declare_lint_pass ! ( EarlyAttributes => [ DEPRECATED_CFG_ATTR , MISMATCHED_TARGET_OS ] ) ;
523+ declare_lint_pass ! ( EarlyAttributes => [
524+ DEPRECATED_CFG_ATTR ,
525+ MISMATCHED_TARGET_OS ,
526+ EMPTY_LINE_AFTER_OUTER_ATTR ,
527+ ] ) ;
555528
556529impl EarlyLintPass for EarlyAttributes {
530+ fn check_item ( & mut self , cx : & EarlyContext < ' _ > , item : & rustc_ast:: ast:: Item ) {
531+ check_empty_line_after_outer_attr ( cx, item) ;
532+ }
533+
557534 fn check_attribute ( & mut self , cx : & EarlyContext < ' _ > , attr : & Attribute ) {
558535 check_deprecated_cfg_attr ( cx, attr) ;
559536 check_mismatched_target_os ( cx, attr) ;
560537 }
561538}
562539
540+ fn check_empty_line_after_outer_attr ( cx : & EarlyContext < ' _ > , item : & rustc_ast:: ast:: Item ) {
541+ for attr in & item. attrs {
542+ let attr_item = if let AttrKind :: Normal ( ref attr) = attr. kind {
543+ attr
544+ } else {
545+ return ;
546+ } ;
547+
548+ if attr. style == AttrStyle :: Outer {
549+ if attr_item. args . inner_tokens ( ) . is_empty ( ) || !is_present_in_source ( cx, attr. span ) {
550+ return ;
551+ }
552+
553+ let begin_of_attr_to_item = Span :: new ( attr. span . lo ( ) , item. span . lo ( ) , item. span . ctxt ( ) ) ;
554+ let end_of_attr_to_item = Span :: new ( attr. span . hi ( ) , item. span . lo ( ) , item. span . ctxt ( ) ) ;
555+
556+ if let Some ( snippet) = snippet_opt ( cx, end_of_attr_to_item) {
557+ let lines = snippet. split ( '\n' ) . collect :: < Vec < _ > > ( ) ;
558+ let lines = without_block_comments ( lines) ;
559+
560+ if lines. iter ( ) . filter ( |l| l. trim ( ) . is_empty ( ) ) . count ( ) > 2 {
561+ span_lint (
562+ cx,
563+ EMPTY_LINE_AFTER_OUTER_ATTR ,
564+ begin_of_attr_to_item,
565+ "Found an empty line after an outer attribute. \
566+ Perhaps you forgot to add a `!` to make it an inner attribute?",
567+ ) ;
568+ }
569+ }
570+ }
571+ }
572+ }
573+
563574fn check_deprecated_cfg_attr ( cx : & EarlyContext < ' _ > , attr : & Attribute ) {
564575 if_chain ! {
565576 // check cfg_attr
0 commit comments