@@ -585,15 +585,21 @@ impl EarlyLintPass for EarlyAttributes {
585585}
586586
587587fn check_empty_line_after_outer_attr ( cx : & EarlyContext < ' _ > , item : & rustc_ast:: Item ) {
588- for attr in & item. attrs {
588+ let mut iter = item. attrs . iter ( ) . peekable ( ) ;
589+ while let Some ( attr) = iter. next ( ) {
589590 if matches ! ( attr. kind, AttrKind :: Normal ( ..) )
590591 && attr. style == AttrStyle :: Outer
591592 && is_present_in_source ( cx, attr. span )
592593 {
593594 let begin_of_attr_to_item = Span :: new ( attr. span . lo ( ) , item. span . lo ( ) , item. span . ctxt ( ) , item. span . parent ( ) ) ;
594- let end_of_attr_to_item = Span :: new ( attr. span . hi ( ) , item. span . lo ( ) , item. span . ctxt ( ) , item. span . parent ( ) ) ;
595+ let end_of_attr_to_next_attr_or_item = Span :: new (
596+ attr. span . hi ( ) ,
597+ iter. peek ( ) . map_or ( item. span . lo ( ) , |next_attr| next_attr. span . lo ( ) ) ,
598+ item. span . ctxt ( ) ,
599+ item. span . parent ( ) ,
600+ ) ;
595601
596- if let Some ( snippet) = snippet_opt ( cx, end_of_attr_to_item ) {
602+ if let Some ( snippet) = snippet_opt ( cx, end_of_attr_to_next_attr_or_item ) {
597603 let lines = snippet. split ( '\n' ) . collect :: < Vec < _ > > ( ) ;
598604 let lines = without_block_comments ( lines) ;
599605
@@ -623,8 +629,15 @@ fn check_deprecated_cfg_attr(cx: &EarlyContext<'_>, attr: &Attribute, msrv: Opti
623629 if feature_item. has_name( sym:: rustfmt) ;
624630 // check for `rustfmt_skip` and `rustfmt::skip`
625631 if let Some ( skip_item) = & items[ 1 ] . meta_item( ) ;
626- if skip_item. has_name( sym!( rustfmt_skip) ) ||
627- skip_item. path. segments. last( ) . expect( "empty path in attribute" ) . ident. name == sym:: skip;
632+ if skip_item. has_name( sym!( rustfmt_skip) )
633+ || skip_item
634+ . path
635+ . segments
636+ . last( )
637+ . expect( "empty path in attribute" )
638+ . ident
639+ . name
640+ == sym:: skip;
628641 // Only lint outer attributes, because custom inner attributes are unstable
629642 // Tracking issue: https://github.com/rust-lang/rust/issues/54726
630643 if attr. style == AttrStyle :: Outer ;
0 commit comments