-
Notifications
You must be signed in to change notification settings - Fork 13k
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
rustdoc: Return a String from collapsed_doc_value, not an Option #92078
Changes from all commits
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
- use rustc's map instead of separate traits in scope | ||
- have a map from def id + link index to resolved DefId | ||
- need to have all 3 namespaces in case the link doesn't resolve |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -68,9 +68,12 @@ pub struct Item { | |
/// By default all documented items are public, but you can tell rustdoc to output private items | ||
/// so this field is needed to differentiate. | ||
pub visibility: Visibility, | ||
/// The full markdown docstring of this item. Absent if there is no documentation at all, | ||
/// Some("") if there is some documentation but it is empty (EG `#[doc = ""]`). | ||
pub docs: Option<String>, | ||
/// The full markdown docstring of this item. | ||
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.
This change seems good to me, but I think this sould be added to the Also their should probably be a test for this 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. Sure thing, done :) |
||
/// | ||
/// This field has already been pre-parsed, including combining lines and de-indenting | ||
/// whitespace. Each line is delimited by a newline, but the docs will not end with a trailing | ||
/// newline (unless added explicitly by the user with `#[doc = "\n"]`). | ||
pub docs: String, | ||
/// This mapping resolves [intra-doc links](https://github.com/rust-lang/rfcs/blob/master/text/1946-intra-rustdoc-links.md) from the docstring to their IDs | ||
pub links: HashMap<String, Id>, | ||
/// Stringified versions of the attributes on this item (e.g. `"#[inline]"`) | ||
|
@@ -511,7 +514,7 @@ pub struct Static { | |
} | ||
|
||
/// rustdoc format-version. | ||
pub const FORMAT_VERSION: u32 = 9; | ||
pub const FORMAT_VERSION: u32 = 10; | ||
|
||
#[cfg(test)] | ||
mod tests; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// @has empty_lines.json "$.index[*][?(@.name == 'foo')]" | ||
// @has - "$.index[*][?(@.name == 'foo')].docs" \"\\n\\n\" | ||
/// | ||
/// | ||
/// | ||
// ^ note that the above line does *not* include a trailing new line in the docs | ||
pub fn foo() {} | ||
|
||
// @has empty_lines.json "$.index[*][?(@.name == 'bar')].docs" "\"first line\\nsecond line \"" | ||
#[doc = "\n first line"] | ||
#[doc = "\n second line \n"] | ||
pub fn bar() {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we sure this slight behavior change here and elsewhere doesn't matter? Before, this checked for if there were no DocFragments; now, it checks if the collapsed docs is an empty string.
I think it's probably "more correct" now, but I just wanted to double-check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you look at https://github.com/rust-lang/rust/blob/c7476adc38bc9348398afcf24117d7d48e7ba9f1/src/librustdoc/html/markdown.rs#L732, it doesn't do anything for empty strings any way; having a check here at all is a microoptimization we could probably remove. So the change shouldn't have an impact.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But this code is looking for doctests, not rendering Markdown.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think there should be a behavior change, but there is a very slight possibility.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This
if
callsfind_testable_code
immediately below. The parser there is parsing the code for doctests.