@@ -73,7 +73,6 @@ crate struct TraitWithExtraInfo {
73
73
#[ derive( Clone , Debug ) ]
74
74
crate struct ExternalCrate {
75
75
crate crate_num : CrateNum ,
76
- crate attrs : Attributes ,
77
76
}
78
77
79
78
impl ExternalCrate {
@@ -663,12 +662,35 @@ impl<'a> Iterator for ListAttributesIter<'a> {
663
662
crate trait AttributesExt {
664
663
/// Finds an attribute as List and returns the list of attributes nested inside.
665
664
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 > ;
666
671
}
667
672
668
673
impl AttributesExt for [ ast:: Attribute ] {
669
674
fn lists ( & self , name : Symbol ) -> ListAttributesIter < ' _ > {
670
675
ListAttributesIter { attrs : self . iter ( ) , current_list : Vec :: new ( ) . into_iter ( ) , name }
671
676
}
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
+ }
672
694
}
673
695
674
696
crate trait NestedAttributesExt {
@@ -778,8 +800,6 @@ crate struct Attributes {
778
800
crate doc_strings : Vec < DocFragment > ,
779
801
crate other_attrs : Vec < ast:: Attribute > ,
780
802
crate cfg : Option < Arc < Cfg > > ,
781
- crate span : Option < rustc_span:: Span > ,
782
- crate inner_docs : bool ,
783
803
}
784
804
785
805
#[ derive( Clone , Debug , Default , PartialEq , Eq , Hash ) ]
@@ -811,6 +831,10 @@ pub struct RenderedLink {
811
831
}
812
832
813
833
impl Attributes {
834
+ crate fn lists ( & self , name : Symbol ) -> ListAttributesIter < ' _ > {
835
+ self . other_attrs . lists ( name)
836
+ }
837
+
814
838
/// Extracts the content from an attribute `#[doc(cfg(content))]`.
815
839
crate fn extract_cfg ( mi : & ast:: MetaItem ) -> Option < & ast:: MetaItem > {
816
840
use rustc_ast:: NestedMetaItem :: MetaItem ;
@@ -895,7 +919,6 @@ impl Attributes {
895
919
additional_attrs : Option < ( & [ ast:: Attribute ] , DefId ) > ,
896
920
) -> Attributes {
897
921
let mut doc_strings: Vec < DocFragment > = vec ! [ ] ;
898
- let mut sp = None ;
899
922
let mut cfg = Cfg :: True ;
900
923
let mut doc_line = 0 ;
901
924
@@ -940,9 +963,6 @@ impl Attributes {
940
963
941
964
doc_strings. push ( frag) ;
942
965
943
- if sp. is_none ( ) {
944
- sp = Some ( attr. span ) ;
945
- }
946
966
None
947
967
} else {
948
968
if attr. has_name ( sym:: doc) {
@@ -1001,17 +1021,10 @@ impl Attributes {
1001
1021
}
1002
1022
}
1003
1023
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
-
1009
1024
Attributes {
1010
1025
doc_strings,
1011
1026
other_attrs,
1012
1027
cfg : if cfg == Cfg :: True { None } else { Some ( Arc :: new ( cfg) ) } ,
1013
- span : sp,
1014
- inner_docs,
1015
1028
}
1016
1029
}
1017
1030
@@ -1079,7 +1092,6 @@ impl PartialEq for Attributes {
1079
1092
fn eq ( & self , rhs : & Self ) -> bool {
1080
1093
self . doc_strings == rhs. doc_strings
1081
1094
&& self . cfg == rhs. cfg
1082
- && self . span == rhs. span
1083
1095
&& self
1084
1096
. other_attrs
1085
1097
. iter ( )
@@ -1094,19 +1106,12 @@ impl Hash for Attributes {
1094
1106
fn hash < H : Hasher > ( & self , hasher : & mut H ) {
1095
1107
self . doc_strings . hash ( hasher) ;
1096
1108
self . cfg . hash ( hasher) ;
1097
- self . span . hash ( hasher) ;
1098
1109
for attr in & self . other_attrs {
1099
1110
attr. id . hash ( hasher) ;
1100
1111
}
1101
1112
}
1102
1113
}
1103
1114
1104
- impl AttributesExt for Attributes {
1105
- fn lists ( & self , name : Symbol ) -> ListAttributesIter < ' _ > {
1106
- self . other_attrs . lists ( name)
1107
- }
1108
- }
1109
-
1110
1115
#[ derive( Clone , PartialEq , Eq , Debug , Hash ) ]
1111
1116
crate enum GenericBound {
1112
1117
TraitBound ( PolyTrait , hir:: TraitBoundModifier ) ,
@@ -1269,7 +1274,6 @@ crate struct FnDecl {
1269
1274
crate inputs : Arguments ,
1270
1275
crate output : FnRetTy ,
1271
1276
crate c_variadic : bool ,
1272
- crate attrs : Attributes ,
1273
1277
}
1274
1278
1275
1279
impl FnDecl {
0 commit comments