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