@@ -585,15 +585,21 @@ impl EarlyLintPass for EarlyAttributes {
585
585
}
586
586
587
587
fn 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 ( ) {
589
590
if matches ! ( attr. kind, AttrKind :: Normal ( ..) )
590
591
&& attr. style == AttrStyle :: Outer
591
592
&& is_present_in_source ( cx, attr. span )
592
593
{
593
594
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
+ ) ;
595
601
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 ) {
597
603
let lines = snippet. split ( '\n' ) . collect :: < Vec < _ > > ( ) ;
598
604
let lines = without_block_comments ( lines) ;
599
605
@@ -623,8 +629,15 @@ fn check_deprecated_cfg_attr(cx: &EarlyContext<'_>, attr: &Attribute, msrv: Opti
623
629
if feature_item. has_name( sym:: rustfmt) ;
624
630
// check for `rustfmt_skip` and `rustfmt::skip`
625
631
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;
628
641
// Only lint outer attributes, because custom inner attributes are unstable
629
642
// Tracking issue: https://github.com/rust-lang/rust/issues/54726
630
643
if attr. style == AttrStyle :: Outer ;
0 commit comments