@@ -401,12 +401,18 @@ impl Item {
401
401
. unwrap_or_else ( || self . span ( tcx) . map_or ( rustc_span:: DUMMY_SP , |span| span. inner ( ) ) )
402
402
}
403
403
404
- /// Finds the `doc` attribute as a NameValue and returns the corresponding
405
- /// value found.
406
- pub ( crate ) fn doc_value ( & self ) -> Option < String > {
404
+ /// Combine all doc strings into a single value handling indentation and newlines as needed.
405
+ pub ( crate ) fn doc_value ( & self ) -> String {
407
406
self . attrs . doc_value ( )
408
407
}
409
408
409
+ /// Combine all doc strings into a single value handling indentation and newlines as needed.
410
+ /// Returns `None` is there's no documentation at all, and `Some("")` if there is some
411
+ /// documentation but it is empty (e.g. `#[doc = ""]`).
412
+ pub ( crate ) fn opt_doc_value ( & self ) -> Option < String > {
413
+ self . attrs . opt_doc_value ( )
414
+ }
415
+
410
416
pub ( crate ) fn from_def_id_and_parts (
411
417
def_id : DefId ,
412
418
name : Option < Symbol > ,
@@ -443,12 +449,6 @@ impl Item {
443
449
}
444
450
}
445
451
446
- /// Finds all `doc` attributes as NameValues and returns their corresponding values, joined
447
- /// with newlines.
448
- pub ( crate ) fn collapsed_doc_value ( & self ) -> Option < String > {
449
- self . attrs . collapsed_doc_value ( )
450
- }
451
-
452
452
pub ( crate ) fn links ( & self , cx : & Context < ' _ > ) -> Vec < RenderedLink > {
453
453
use crate :: html:: format:: { href, link_tooltip} ;
454
454
@@ -1068,17 +1068,6 @@ impl<I: Iterator<Item = ast::NestedMetaItem>> NestedAttributesExt for I {
1068
1068
}
1069
1069
}
1070
1070
1071
- /// Collapse a collection of [`DocFragment`]s into one string,
1072
- /// handling indentation and newlines as needed.
1073
- pub ( crate ) fn collapse_doc_fragments ( doc_strings : & [ DocFragment ] ) -> String {
1074
- let mut acc = String :: new ( ) ;
1075
- for frag in doc_strings {
1076
- add_doc_fragment ( & mut acc, frag) ;
1077
- }
1078
- acc. pop ( ) ;
1079
- acc
1080
- }
1081
-
1082
1071
/// A link that has not yet been rendered.
1083
1072
///
1084
1073
/// This link will be turned into a rendered link by [`Item::links`].
@@ -1163,29 +1152,23 @@ impl Attributes {
1163
1152
Attributes { doc_strings, other_attrs }
1164
1153
}
1165
1154
1166
- /// Finds the `doc` attribute as a NameValue and returns the corresponding
1167
- /// value found.
1168
- pub ( crate ) fn doc_value ( & self ) -> Option < String > {
1169
- let mut iter = self . doc_strings . iter ( ) ;
1170
-
1171
- let ori = iter. next ( ) ?;
1172
- let mut out = String :: new ( ) ;
1173
- add_doc_fragment ( & mut out, ori) ;
1174
- for new_frag in iter {
1175
- add_doc_fragment ( & mut out, new_frag) ;
1176
- }
1177
- out. pop ( ) ;
1178
- if out. is_empty ( ) { None } else { Some ( out) }
1155
+ /// Combine all doc strings into a single value handling indentation and newlines as needed.
1156
+ pub ( crate ) fn doc_value ( & self ) -> String {
1157
+ self . opt_doc_value ( ) . unwrap_or_default ( )
1179
1158
}
1180
1159
1181
- /// Finds all `doc` attributes as NameValues and returns their corresponding values, joined
1182
- /// with newlines.
1183
- pub ( crate ) fn collapsed_doc_value ( & self ) -> Option < String > {
1184
- if self . doc_strings . is_empty ( ) {
1185
- None
1186
- } else {
1187
- Some ( collapse_doc_fragments ( & self . doc_strings ) )
1188
- }
1160
+ /// Combine all doc strings into a single value handling indentation and newlines as needed.
1161
+ /// Returns `None` is there's no documentation at all, and `Some("")` if there is some
1162
+ /// documentation but it is empty (e.g. `#[doc = ""]`).
1163
+ pub ( crate ) fn opt_doc_value ( & self ) -> Option < String > {
1164
+ ( !self . doc_strings . is_empty ( ) ) . then ( || {
1165
+ let mut res = String :: new ( ) ;
1166
+ for frag in & self . doc_strings {
1167
+ add_doc_fragment ( & mut res, frag) ;
1168
+ }
1169
+ res. pop ( ) ;
1170
+ res
1171
+ } )
1189
1172
}
1190
1173
1191
1174
pub ( crate ) fn get_doc_aliases ( & self ) -> Box < [ Symbol ] > {
0 commit comments