@@ -73,7 +73,6 @@ crate struct TraitWithExtraInfo {
7373#[ derive( Clone , Debug ) ]
7474crate struct ExternalCrate {
7575 crate crate_num : CrateNum ,
76- crate attrs : Attributes ,
7776}
7877
7978impl ExternalCrate {
@@ -663,12 +662,35 @@ impl<'a> Iterator for ListAttributesIter<'a> {
663662crate trait AttributesExt {
664663 /// Finds an attribute as List and returns the list of attributes nested inside.
665664 fn lists ( & self , name : Symbol ) -> ListAttributesIter < ' _ > ;
665+
666+ fn span ( & self ) -> Option < rustc_span:: Span > ;
667+
668+ fn inner_docs ( & self ) -> bool ;
669+
670+ fn other_attrs ( & self ) -> Vec < ast:: Attribute > ;
666671}
667672
668673impl AttributesExt for [ ast:: Attribute ] {
669674 fn lists ( & self , name : Symbol ) -> ListAttributesIter < ' _ > {
670675 ListAttributesIter { attrs : self . iter ( ) , current_list : Vec :: new ( ) . into_iter ( ) , name }
671676 }
677+
678+ /// Return the span of the first doc-comment, if it exists.
679+ fn span ( & self ) -> Option < rustc_span:: Span > {
680+ self . iter ( ) . find ( |attr| attr. doc_str ( ) . is_some ( ) ) . map ( |attr| attr. span )
681+ }
682+
683+ /// Returns whether the first doc-comment is an inner attribute.
684+ ///
685+ //// If there are no doc-comments, return true.
686+ /// FIXME(#78591): Support both inner and outer attributes on the same item.
687+ fn inner_docs ( & self ) -> bool {
688+ self . iter ( ) . find ( |a| a. doc_str ( ) . is_some ( ) ) . map_or ( true , |a| a. style == AttrStyle :: Inner )
689+ }
690+
691+ fn other_attrs ( & self ) -> Vec < ast:: Attribute > {
692+ self . iter ( ) . filter ( |attr| attr. doc_str ( ) . is_none ( ) ) . cloned ( ) . collect ( )
693+ }
672694}
673695
674696crate trait NestedAttributesExt {
@@ -778,8 +800,6 @@ crate struct Attributes {
778800 crate doc_strings : Vec < DocFragment > ,
779801 crate other_attrs : Vec < ast:: Attribute > ,
780802 crate cfg : Option < Arc < Cfg > > ,
781- crate span : Option < rustc_span:: Span > ,
782- crate inner_docs : bool ,
783803}
784804
785805#[ derive( Clone , Debug , Default , PartialEq , Eq , Hash ) ]
@@ -811,6 +831,10 @@ pub struct RenderedLink {
811831}
812832
813833impl Attributes {
834+ crate fn lists ( & self , name : Symbol ) -> ListAttributesIter < ' _ > {
835+ self . other_attrs . lists ( name)
836+ }
837+
814838 /// Extracts the content from an attribute `#[doc(cfg(content))]`.
815839 crate fn extract_cfg ( mi : & ast:: MetaItem ) -> Option < & ast:: MetaItem > {
816840 use rustc_ast:: NestedMetaItem :: MetaItem ;
@@ -895,7 +919,6 @@ impl Attributes {
895919 additional_attrs : Option < ( & [ ast:: Attribute ] , DefId ) > ,
896920 ) -> Attributes {
897921 let mut doc_strings: Vec < DocFragment > = vec ! [ ] ;
898- let mut sp = None ;
899922 let mut cfg = Cfg :: True ;
900923 let mut doc_line = 0 ;
901924
@@ -940,9 +963,6 @@ impl Attributes {
940963
941964 doc_strings. push ( frag) ;
942965
943- if sp. is_none ( ) {
944- sp = Some ( attr. span ) ;
945- }
946966 None
947967 } else {
948968 if attr. has_name ( sym:: doc) {
@@ -1001,17 +1021,10 @@ impl Attributes {
10011021 }
10021022 }
10031023
1004- let inner_docs = attrs
1005- . iter ( )
1006- . find ( |a| a. doc_str ( ) . is_some ( ) )
1007- . map_or ( true , |a| a. style == AttrStyle :: Inner ) ;
1008-
10091024 Attributes {
10101025 doc_strings,
10111026 other_attrs,
10121027 cfg : if cfg == Cfg :: True { None } else { Some ( Arc :: new ( cfg) ) } ,
1013- span : sp,
1014- inner_docs,
10151028 }
10161029 }
10171030
@@ -1079,7 +1092,6 @@ impl PartialEq for Attributes {
10791092 fn eq ( & self , rhs : & Self ) -> bool {
10801093 self . doc_strings == rhs. doc_strings
10811094 && self . cfg == rhs. cfg
1082- && self . span == rhs. span
10831095 && self
10841096 . other_attrs
10851097 . iter ( )
@@ -1094,19 +1106,12 @@ impl Hash for Attributes {
10941106 fn hash < H : Hasher > ( & self , hasher : & mut H ) {
10951107 self . doc_strings . hash ( hasher) ;
10961108 self . cfg . hash ( hasher) ;
1097- self . span . hash ( hasher) ;
10981109 for attr in & self . other_attrs {
10991110 attr. id . hash ( hasher) ;
11001111 }
11011112 }
11021113}
11031114
1104- impl AttributesExt for Attributes {
1105- fn lists ( & self , name : Symbol ) -> ListAttributesIter < ' _ > {
1106- self . other_attrs . lists ( name)
1107- }
1108- }
1109-
11101115#[ derive( Clone , PartialEq , Eq , Debug , Hash ) ]
11111116crate enum GenericBound {
11121117 TraitBound ( PolyTrait , hir:: TraitBoundModifier ) ,
@@ -1269,7 +1274,6 @@ crate struct FnDecl {
12691274 crate inputs : Arguments ,
12701275 crate output : FnRetTy ,
12711276 crate c_variadic : bool ,
1272- crate attrs : Attributes ,
12731277}
12741278
12751279impl FnDecl {
0 commit comments