@@ -401,12 +401,18 @@ impl Item {
401401 . unwrap_or_else ( || self . span ( tcx) . map_or ( rustc_span:: DUMMY_SP , |span| span. inner ( ) ) )
402402 }
403403
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 {
407406 self . attrs . doc_value ( )
408407 }
409408
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+
410416 pub ( crate ) fn from_def_id_and_parts (
411417 def_id : DefId ,
412418 name : Option < Symbol > ,
@@ -443,12 +449,6 @@ impl Item {
443449 }
444450 }
445451
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-
452452 pub ( crate ) fn links ( & self , cx : & Context < ' _ > ) -> Vec < RenderedLink > {
453453 use crate :: html:: format:: { href, link_tooltip} ;
454454
@@ -1068,17 +1068,6 @@ impl<I: Iterator<Item = ast::NestedMetaItem>> NestedAttributesExt for I {
10681068 }
10691069}
10701070
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-
10821071/// A link that has not yet been rendered.
10831072///
10841073/// This link will be turned into a rendered link by [`Item::links`].
@@ -1163,29 +1152,23 @@ impl Attributes {
11631152 Attributes { doc_strings, other_attrs }
11641153 }
11651154
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 ( )
11791158 }
11801159
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+ } )
11891172 }
11901173
11911174 pub ( crate ) fn get_doc_aliases ( & self ) -> Box < [ Symbol ] > {
0 commit comments