@@ -1089,35 +1089,35 @@ impl Attributes {
1089
1089
attrs : & [ ast:: Attribute ] ,
1090
1090
additional_attrs : Option < ( & [ ast:: Attribute ] , DefId ) > ,
1091
1091
) -> Attributes {
1092
- let mut doc_strings: Vec < DocFragment > = vec ! [ ] ;
1093
- let clean_attr = |( attr, parent_module) : ( & ast:: Attribute , Option < DefId > ) | {
1094
- if let Some ( ( value, kind) ) = attr. doc_str_and_comment_kind ( ) {
1095
- trace ! ( "got doc_str={:?}" , value) ;
1096
- let value = beautify_doc_string ( value, kind) ;
1092
+ // Additional documentation should be shown before the original documentation.
1093
+ let attrs1 = additional_attrs
1094
+ . into_iter ( )
1095
+ . flat_map ( |( attrs, def_id) | attrs. iter ( ) . map ( move |attr| ( attr, Some ( def_id) ) ) ) ;
1096
+ let attrs2 = attrs. iter ( ) . map ( |attr| ( attr, None ) ) ;
1097
+ Attributes :: from_ast_iter ( attrs1. chain ( attrs2) , false )
1098
+ }
1099
+
1100
+ crate fn from_ast_iter < ' a > (
1101
+ attrs : impl Iterator < Item = ( & ' a ast:: Attribute , Option < DefId > ) > ,
1102
+ doc_only : bool ,
1103
+ ) -> Attributes {
1104
+ let mut doc_strings = Vec :: new ( ) ;
1105
+ let mut other_attrs = Vec :: new ( ) ;
1106
+ for ( attr, parent_module) in attrs {
1107
+ if let Some ( ( doc_str, comment_kind) ) = attr. doc_str_and_comment_kind ( ) {
1108
+ trace ! ( "got doc_str={doc_str:?}" ) ;
1109
+ let doc = beautify_doc_string ( doc_str, comment_kind) ;
1097
1110
let kind = if attr. is_doc_comment ( ) {
1098
1111
DocFragmentKind :: SugaredDoc
1099
1112
} else {
1100
1113
DocFragmentKind :: RawDoc
1101
1114
} ;
1102
-
1103
- let frag =
1104
- DocFragment { span : attr. span , doc : value, kind, parent_module, indent : 0 } ;
1105
-
1106
- doc_strings. push ( frag) ;
1107
-
1108
- None
1109
- } else {
1110
- Some ( attr. clone ( ) )
1115
+ let fragment = DocFragment { span : attr. span , doc, kind, parent_module, indent : 0 } ;
1116
+ doc_strings. push ( fragment) ;
1117
+ } else if !doc_only {
1118
+ other_attrs. push ( attr. clone ( ) ) ;
1111
1119
}
1112
- } ;
1113
-
1114
- // Additional documentation should be shown before the original documentation
1115
- let other_attrs = additional_attrs
1116
- . into_iter ( )
1117
- . flat_map ( |( attrs, id) | attrs. iter ( ) . map ( move |attr| ( attr, Some ( id) ) ) )
1118
- . chain ( attrs. iter ( ) . map ( |attr| ( attr, None ) ) )
1119
- . filter_map ( clean_attr)
1120
- . collect ( ) ;
1120
+ }
1121
1121
1122
1122
Attributes { doc_strings, other_attrs }
1123
1123
}
@@ -1138,23 +1138,17 @@ impl Attributes {
1138
1138
}
1139
1139
1140
1140
/// Return the doc-comments on this item, grouped by the module they came from.
1141
- ///
1142
1141
/// The module can be different if this is a re-export with added documentation.
1143
- crate fn collapsed_doc_value_by_module_level ( & self ) -> FxHashMap < Option < DefId > , String > {
1144
- let mut ret = FxHashMap :: default ( ) ;
1145
- if self . doc_strings . len ( ) == 0 {
1146
- return ret;
1147
- }
1148
- let last_index = self . doc_strings . len ( ) - 1 ;
1149
-
1150
- for ( i, new_frag) in self . doc_strings . iter ( ) . enumerate ( ) {
1151
- let out = ret. entry ( new_frag. parent_module ) . or_default ( ) ;
1152
- add_doc_fragment ( out, new_frag) ;
1153
- if i == last_index {
1154
- out. pop ( ) ;
1155
- }
1142
+ ///
1143
+ /// The last newline is not trimmed so the produced strings are reusable between
1144
+ /// early and late doc link resolution regardless of their position.
1145
+ crate fn prepare_to_doc_link_resolution ( & self ) -> FxHashMap < Option < DefId > , String > {
1146
+ let mut res = FxHashMap :: default ( ) ;
1147
+ for fragment in & self . doc_strings {
1148
+ let out_str = res. entry ( fragment. parent_module ) . or_default ( ) ;
1149
+ add_doc_fragment ( out_str, fragment) ;
1156
1150
}
1157
- ret
1151
+ res
1158
1152
}
1159
1153
1160
1154
/// Finds all `doc` attributes as NameValues and returns their corresponding values, joined
0 commit comments