@@ -1089,35 +1089,35 @@ impl Attributes {
10891089 attrs : & [ ast:: Attribute ] ,
10901090 additional_attrs : Option < ( & [ ast:: Attribute ] , DefId ) > ,
10911091 ) -> 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) ;
10971110 let kind = if attr. is_doc_comment ( ) {
10981111 DocFragmentKind :: SugaredDoc
10991112 } else {
11001113 DocFragmentKind :: RawDoc
11011114 } ;
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 ( ) ) ;
11111119 }
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+ }
11211121
11221122 Attributes { doc_strings, other_attrs }
11231123 }
@@ -1138,23 +1138,17 @@ impl Attributes {
11381138 }
11391139
11401140 /// Return the doc-comments on this item, grouped by the module they came from.
1141- ///
11421141 /// 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) ;
11561150 }
1157- ret
1151+ res
11581152 }
11591153
11601154 /// Finds all `doc` attributes as NameValues and returns their corresponding values, joined
0 commit comments