-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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: include external files in documentation (RFC 1990) #44781
Conversation
(rust_highfive has picked a reviewer for you, use r? to override) |
Travis failure is because my test for 42760 failed |
update: apparently |
So i wound up modifying |
6f188ec
to
b25e8bd
Compare
Travis was green, so i'm declaring this Ready To Be Looked At. I updated one test to make sure combining included docs and inline docs worked and squashed the commits. The libsyntax change is still in its own commit, though, since it was only included to make the fix for #42760 work properly, and i'm still not sure whether it's the totally right thing to do. |
src/librustdoc/clean/mod.rs
Outdated
match Attributes::load_include(include_path, &filename) { | ||
Ok(frag) => { | ||
let line = doc_line; | ||
doc_line += frag.len(); |
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.
Oh so you decided to put in the "real" line number instead of the one from the original file?
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.
Yeah. My thought was that if you're trying to trace a line number from the total markdown blob, then you could use that to get the doc fragment, since each attribute is joined with a line break anyway.
It'd be nice to have some outputs (or even tests?) for the case of failing doc codes. |
That's what i was forgetting! Give me a moment, i can make a quick run. |
b25e8bd
to
7e482de
Compare
With the following files:
#![feature(external_doc)]
/// hey yo check out these docs, i can splice them in from another file
///
/// ```rust
/// panic!("oh no");
/// ```
///
#[doc(include = "some-file.md")]
pub struct SomeStruct;
/// Item docs.
///
#[doc="Hello there!"]
///
/// # Example
///
/// ```rust
/// // some code here
/// panic!("oh no");
/// ```
pub struct OtherStruct;
#[doc(include = "bad-docs.md")]
#[doc(include = "no-docs.md")]
pub struct AllTheStruct;
( Running This is with the latest force push. (I neglected to ask rustdoctest to combine doc fragments, so that's fixed now.) EDIT: The current line numbering refers to the line within the final markdown, not the line in the source file. So i guess to properly translate between this line number and the source line, you need to store both the "markdown line" and the "source line". This could get hairy to properly account for multiple |
And a column as well for the "real" line number (so a |
@GuillaumeGomez I added a |
Please post a test failure output. :) |
I haven't touched the failure reporting code, so it'll look the same as in #44781 (comment). Do you want me to make that part of this PR, or would you like to merge this as-is and take it up yourself afterward? |
I don't mind merging as is. Just tell me what you prefer to do. |
If i remember right, we discussed fixing up the error reporting in a separate PR, so that's what i was assuming we would do here (and my preference, just so we can get this in |
This doesn't work cross-crate. If you re-export an item that uses |
@ollie27 Oh yikes, that's a good point. On the other hand, i don't really see a good way to reliably do it cross-crate without asking rustc to load the file in. In the RFC discussion we talked about making it an alias for |
Having a special case for doc include in rustc might be easier than supporting arbitrary macros in arbitrary attributes. (Or maybe not, I don’t know.) |
☔ The latest upstream changes (presumably #45046) made this pull request unmergeable. Please resolve the merge conflicts. |
@QuietMisdreavus I've set this back as with author for the merge conflicts. After that, I'm also not clear after that if you're going to do more work or it's going back to review by @GuillaumeGomez? |
@aidanhs I'm actually not sure either. I'm concerned it may need to be scrapped entirely in favor of the |
Won't kill to add them in the loop. :) cc @rust-lang/compiler |
triage ping for @QuietMisdreavus, do you know what the next steps here are? |
src/librustdoc/html/render.rs
Outdated
if let Some(s) = item.doc_value() { | ||
render_markdown(w, s, item.source.clone(), cx.render_type, prefix, &cx.shared)?; | ||
if let Some(s) = cx.shared.maybe_collapsed_doc_value(item) { | ||
trace!("Doc block: =====\n{}\n=====", s); |
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.
Shouldn't debug!
be used instead? (Don't really know the good macro we're supposed to use in such cases...)
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.
Probably? I'm not that solid on what counts as what either, but i'll go ahead and switch it over.
match curr_frag { | ||
DocFragment::SugaredDoc(_, _, ref mut doc_string) | ||
| DocFragment::RawDoc(_, _, ref mut doc_string) => { | ||
//add a newline for extra padding between segments |
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.
Whitespace after //
please.
src/libsyntax/ext/expand.rs
Outdated
let err_count = self.cx.parse_sess.span_diagnostic.err_count(); | ||
self.check_attribute(&at); | ||
if self.cx.parse_sess.span_diagnostic.err_count() > err_count { | ||
//avoid loading the file if they haven't enabled the feature |
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.
Whitepace.
All good for me from code reading. Just a few nits and it's good to go imo. |
Partial implementation of rust-lang/rfcs#1990 (needs error reporting work) cc rust-lang#44732
abc9aca
to
52ee203
Compare
I've force-pushed to address the review comments. |
Then it's all good for me. r=me once CI is green. |
@bors r=GuillaumeGomez |
📌 Commit 52ee203 has been approved by |
⌛ Testing commit 52ee203 with merge 0893ecc8955191f702513ff3a19d420f9650fae5... |
💔 Test failed - status-travis |
Failure... doesn't look legit? I'm not caught up on the known spurious failures.
|
rustdoc: include external files in documentation (RFC 1990) Part of rust-lang/rfcs#1990 (needs work on the error reporting, which i'm deferring to after this initial PR) cc #44732 Also fixes #42760, because the prep work for the error reporting made it easy to fix that at the same time.
☀️ Test successful - status-appveyor, status-travis |
Part of rust-lang/rfcs#1990 (needs work on the error reporting, which i'm deferring to after this initial PR)
cc #44732
Also fixes #42760, because the prep work for the error reporting made it easy to fix that at the same time.