-
Notifications
You must be signed in to change notification settings - Fork 13.4k
rustdoc: Remove distinction between "regular" and "collapsed" docs #91072
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
7be69ba
da26b51
22dc5c4
8be135b
1891548
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
use std::cell::RefCell; | ||
use std::default::Default; | ||
use std::hash::{Hash, Hasher}; | ||
use std::iter::FromIterator; | ||
use std::lazy::SyncOnceCell as OnceCell; | ||
use std::path::PathBuf; | ||
use std::rc::Rc; | ||
|
@@ -121,12 +120,11 @@ crate struct Crate { | |
crate primitives: ThinVec<(DefId, PrimitiveType)>, | ||
/// Only here so that they can be filtered through the rustdoc passes. | ||
crate external_traits: Rc<RefCell<FxHashMap<DefId, TraitWithExtraInfo>>>, | ||
crate collapsed: bool, | ||
} | ||
|
||
// `Crate` is frequently moved by-value. Make sure it doesn't unintentionally get bigger. | ||
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))] | ||
rustc_data_structures::static_assert_size!(Crate, 104); | ||
rustc_data_structures::static_assert_size!(Crate, 96); | ||
|
||
impl Crate { | ||
crate fn name(&self, tcx: TyCtxt<'_>) -> Symbol { | ||
|
@@ -411,12 +409,6 @@ impl Item { | |
crate::passes::span_of_attrs(&self.attrs).unwrap_or_else(|| self.span(tcx).inner()) | ||
} | ||
|
||
/// Finds the `doc` attribute as a NameValue and returns the corresponding | ||
/// value found. | ||
crate fn doc_value(&self) -> Option<String> { | ||
self.attrs.doc_value() | ||
} | ||
|
||
/// Convenience wrapper around [`Self::from_def_id_and_parts`] which converts | ||
/// `hir_id` to a [`DefId`] | ||
pub fn from_hir_id_and_parts( | ||
|
@@ -468,8 +460,8 @@ impl Item { | |
|
||
/// Finds all `doc` attributes as NameValues and returns their corresponding values, joined | ||
/// with newlines. | ||
crate fn collapsed_doc_value(&self) -> Option<String> { | ||
self.attrs.collapsed_doc_value() | ||
crate fn doc_value(&self) -> Option<String> { | ||
self.attrs.doc_value() | ||
} | ||
|
||
crate fn links(&self, cx: &Context<'_>) -> Vec<RenderedLink> { | ||
|
@@ -952,16 +944,14 @@ fn add_doc_fragment(out: &mut String, frag: &DocFragment) { | |
} | ||
} | ||
|
||
impl<'a> FromIterator<&'a DocFragment> for String { | ||
fn from_iter<T>(iter: T) -> Self | ||
where | ||
T: IntoIterator<Item = &'a DocFragment>, | ||
{ | ||
iter.into_iter().fold(String::new(), |mut acc, frag| { | ||
add_doc_fragment(&mut acc, frag); | ||
acc | ||
}) | ||
/// Collapse a collection of [`DocFragment`]s into one string, | ||
/// handling indentation and newlines as needed. | ||
crate fn collapse_doc_fragments(doc_strings: &[DocFragment]) -> String { | ||
let mut acc = String::new(); | ||
for frag in doc_strings { | ||
add_doc_fragment(&mut acc, frag); | ||
} | ||
acc | ||
} | ||
|
||
/// A link that has not yet been rendered. | ||
|
@@ -1074,27 +1064,10 @@ impl Attributes { | |
Attributes { doc_strings, other_attrs } | ||
} | ||
|
||
/// Finds the `doc` attribute as a NameValue and returns the corresponding | ||
/// value found. | ||
crate fn doc_value(&self) -> Option<String> { | ||
let mut iter = self.doc_strings.iter(); | ||
|
||
let ori = iter.next()?; | ||
let mut out = String::new(); | ||
add_doc_fragment(&mut out, ori); | ||
for new_frag in iter { | ||
if new_frag.kind != ori.kind || new_frag.parent_module != ori.parent_module { | ||
break; | ||
} | ||
add_doc_fragment(&mut out, new_frag); | ||
} | ||
if out.is_empty() { None } else { Some(out) } | ||
} | ||
|
||
/// Return the doc-comments on this item, grouped by the module they came from. | ||
/// | ||
/// The module can be different if this is a re-export with added documentation. | ||
crate fn collapsed_doc_value_by_module_level(&self) -> FxHashMap<Option<DefId>, String> { | ||
crate fn doc_value_by_module_level(&self) -> FxHashMap<Option<DefId>, String> { | ||
let mut ret = FxHashMap::default(); | ||
|
||
for new_frag in self.doc_strings.iter() { | ||
|
@@ -1106,8 +1079,12 @@ impl Attributes { | |
|
||
/// Finds all `doc` attributes as NameValues and returns their corresponding values, joined | ||
/// with newlines. | ||
crate fn collapsed_doc_value(&self) -> Option<String> { | ||
if self.doc_strings.is_empty() { None } else { Some(self.doc_strings.iter().collect()) } | ||
crate fn doc_value(&self) -> Option<String> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not necessarily in this pr, but it would be nice to remove the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we check the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't really understand why There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Another difference between ///
///
///
pub fn foo() {} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @CraftSpider I see the following comment in
Is that an important distinction? Or can I just make that field a simple |
||
if self.doc_strings.is_empty() { | ||
None | ||
} else { | ||
Some(collapse_doc_fragments(&self.doc_strings)) | ||
} | ||
} | ||
|
||
crate fn get_doc_aliases(&self) -> Box<[String]> { | ||
|
Uh oh!
There was an error while loading. Please reload this page.