Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign uprustdoc: include external files in documentation (RFC 1990) #44781
Conversation
rust-highfive
assigned
GuillaumeGomez
Sep 23, 2017
This comment has been minimized.
This comment has been minimized.
|
(rust_highfive has picked a reviewer for you, use r? to override) |
estebank
added
the
S-waiting-on-review
label
Sep 23, 2017
This comment has been minimized.
This comment has been minimized.
|
Travis failure is because my test for 42760 failed |
This comment has been minimized.
This comment has been minimized.
|
update: apparently |
This comment has been minimized.
This comment has been minimized.
|
So i wound up modifying |
QuietMisdreavus
force-pushed the
QuietMisdreavus:doc-include
branch
from
6f188ec
to
b25e8bd
Sep 23, 2017
QuietMisdreavus
changed the title
[WIP] rustdoc: include external files in documentation (RFC 1990)
rustdoc: include external files in documentation (RFC 1990)
Sep 23, 2017
This comment has been minimized.
This comment has been minimized.
|
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. |
GuillaumeGomez
reviewed
Sep 23, 2017
| match Attributes::load_include(include_path, &filename) { | ||
| Ok(frag) => { | ||
| let line = doc_line; | ||
| doc_line += frag.len(); |
This comment has been minimized.
This comment has been minimized.
GuillaumeGomez
Sep 23, 2017
Member
Oh so you decided to put in the "real" line number instead of the one from the original file?
This comment has been minimized.
This comment has been minimized.
QuietMisdreavus
Sep 23, 2017
Author
Member
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.
This comment has been minimized.
This comment has been minimized.
|
It'd be nice to have some outputs (or even tests?) for the case of failing doc codes. |
This comment has been minimized.
This comment has been minimized.
That's what i was forgetting! Give me a moment, i can make a quick run. |
QuietMisdreavus
force-pushed the
QuietMisdreavus:doc-include
branch
from
b25e8bd
to
7e482de
Sep 23, 2017
This comment has been minimized.
This comment has been minimized.
|
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 |
This comment has been minimized.
This comment has been minimized.
|
And a column as well for the "real" line number (so a |
This comment has been minimized.
This comment has been minimized.
|
@GuillaumeGomez I added a |
This comment has been minimized.
This comment has been minimized.
|
Please post a test failure output. :) |
This comment has been minimized.
This comment has been minimized.
|
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? |
This comment has been minimized.
This comment has been minimized.
|
I don't mind merging as is. Just tell me what you prefer to do. |
This comment has been minimized.
This comment has been minimized.
|
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 comment has been minimized.
This comment has been minimized.
|
This doesn't work cross-crate. If you re-export an item that uses |
This comment has been minimized.
This comment has been minimized.
|
@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 |
This comment has been minimized.
This comment has been minimized.
|
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.) |
This comment has been minimized.
This comment has been minimized.
|
|
aidanhs
added
S-waiting-on-author
and removed
S-waiting-on-review
labels
Oct 12, 2017
This comment has been minimized.
This comment has been minimized.
|
@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? |
This comment has been minimized.
This comment has been minimized.
|
@aidanhs I'm actually not sure either. I'm concerned it may need to be scrapped entirely in favor of the |
This comment has been minimized.
This comment has been minimized.
|
Won't kill to add them in the loop. :) |
nrc
referenced this pull request
Nov 21, 2017
Open
Tracking issue: rfc 1990 - add external doc attribute to rustc #44732
GuillaumeGomez
reviewed
Nov 21, 2017
| mi.meta_item_list().and_then(|list| { | ||
| for meta in list { | ||
| if meta.check_name("include") { | ||
| //the actual compiled `#[doc(include="filename")]` gets expanded to |
This comment has been minimized.
This comment has been minimized.
GuillaumeGomez
reviewed
Nov 21, 2017
| 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); |
This comment has been minimized.
This comment has been minimized.
GuillaumeGomez
Nov 21, 2017
Member
Shouldn't debug! be used instead? (Don't really know the good macro we're supposed to use in such cases...)
This comment has been minimized.
This comment has been minimized.
QuietMisdreavus
Nov 21, 2017
Author
Member
Probably? I'm not that solid on what counts as what either, but i'll go ahead and switch it over.
GuillaumeGomez
reviewed
Nov 21, 2017
| match curr_frag { | ||
| DocFragment::SugaredDoc(_, _, ref mut doc_string) | ||
| | DocFragment::RawDoc(_, _, ref mut doc_string) => { | ||
| //add a newline for extra padding between segments |
This comment has been minimized.
This comment has been minimized.
GuillaumeGomez
reviewed
Nov 21, 2017
| 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 |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
All good for me from code reading. Just a few nits and it's good to go imo. |
kennytm
added
S-waiting-on-author
and removed
S-waiting-on-review
labels
Nov 21, 2017
QuietMisdreavus
added some commits
Sep 22, 2017
QuietMisdreavus
force-pushed the
QuietMisdreavus:doc-include
branch
from
abc9aca
to
52ee203
Nov 21, 2017
This comment has been minimized.
This comment has been minimized.
|
I've force-pushed to address the review comments. |
This comment has been minimized.
This comment has been minimized.
|
Then it's all good for me. r=me once CI is green. |
This comment has been minimized.
This comment has been minimized.
|
@bors r=GuillaumeGomez |
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
bors
added a commit
that referenced
this pull request
Nov 22, 2017
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
|
Failure... doesn't look legit? I'm not caught up on the known spurious failures.
|
This comment has been minimized.
This comment has been minimized.
kennytm
added
S-waiting-on-bors
and removed
S-waiting-on-author
labels
Nov 22, 2017
This comment has been minimized.
This comment has been minimized.
bors
added a commit
that referenced
this pull request
Nov 22, 2017
This comment has been minimized.
This comment has been minimized.
|
|

QuietMisdreavus commentedSep 23, 2017
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.