Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upTracking issue: rfc 1990 - add external doc attribute to rustc #44732
Comments
nrc
added
A-attributes
T-rustdoc
C-tracking-issue
T-dev-tools
T-doc
WG-docs-rustdoc
labels
Sep 21, 2017
added a commit
to QuietMisdreavus/rust
that referenced
this issue
Sep 22, 2017
QuietMisdreavus
referenced this issue
Sep 23, 2017
Merged
rustdoc: include external files in documentation (RFC 1990) #44781
added a commit
to QuietMisdreavus/rust
that referenced
this issue
Sep 23, 2017
added a commit
to QuietMisdreavus/rust
that referenced
this issue
Sep 23, 2017
This comment has been minimized.
This comment has been minimized.
|
At today's Cargo meeting, and interesting question was raised how Cargo should check if it should rebuild the docs when an external file with docs changes. Here's some info on how dependency-tracking works today: When doing Curiously, TL;DR: |
This comment has been minimized.
This comment has been minimized.
|
@matklad So, it sounds like the current behavior is correct but could be made more efficient. That's better than being incorrect. |
This comment has been minimized.
This comment has been minimized.
There's an edge case where it might not do rebuild when it should, if in #[path="../../bar.rs"]
pub mod bar;Or include!("../../bar.rs")That is, if you touch files outside of the Cargo package directory. Other than that yes, current behavior is correct!. |
steveklabnik
added
the
P-medium
label
Oct 31, 2017
chriskrycho
referenced this issue
Nov 8, 2017
Closed
Allow documentation to be read from an external file #15470
added a commit
to QuietMisdreavus/rust
that referenced
this issue
Nov 9, 2017
added a commit
to QuietMisdreavus/rust
that referenced
this issue
Nov 11, 2017
added a commit
to QuietMisdreavus/rust
that referenced
this issue
Nov 11, 2017
added a commit
to QuietMisdreavus/rust
that referenced
this issue
Nov 11, 2017
added a commit
to QuietMisdreavus/rust
that referenced
this issue
Nov 21, 2017
added a commit
to QuietMisdreavus/rust
that referenced
this issue
Nov 21, 2017
added a commit
that referenced
this issue
Nov 22, 2017
added a commit
that referenced
this issue
Nov 22, 2017
This comment has been minimized.
This comment has been minimized.
|
This probably won't cause any issues in the real world, but related to the discussion above about dependency tracking, I noticed that Compare vs.
It looks like rust/src/libsyntax/ext/source_util.rs Line 152 in a0db04b so presumably doing the same thing inside the implementation of rust/src/libsyntax/ext/expand.rs Line 1117 in 632ad19 |
This comment has been minimized.
This comment has been minimized.
|
I neglected to mention, but it looks like there's even a test to ensure that files used in |
This comment has been minimized.
This comment has been minimized.
|
Humorously enough, i asked about that when i was writing it:
Judging from the above discussion in this thread, it may be prudent to add it, but it also may not be necessary. I'd defer to @rust-lang/compiler for that, i guess. |
This comment has been minimized.
This comment has been minimized.
|
I personally would find it quite unfortunate if changing the included file doesn't lead to rebuilding the code. (One day, incremental compilation should make that a very fast rebuild.) I realize that usually it won't affect the generated code, but I could imagine a syntax extension of some kind processing doc comments (after all documentation has been normalized to the equivalent of a |
QuietMisdreavus
referenced this issue
Dec 7, 2017
Closed
turn errors from loading external docs into a proper lint #46567
This comment has been minimized.
This comment has been minimized.
|
The current implementation seems to interact poorly with $ cat test.md
foo
$ cat test.rs
#![doc(include = "test.md")]
#![feature(external_doc)]
#![deny(missing_docs)]
fn main() {}
$ rustc +nightly test.rs
error: missing documentation for crate
--> test.rs:1:1
|
1 | / #![doc(include = "test.md")]
2 | | #![feature(external_doc)]
3 | | #![deny(missing_docs)]
4 | |
5 | | fn main() {}
| |____________^
|
note: lint level defined here
--> test.rs:3:9
|
3 | #![deny(missing_docs)]
| ^^^^^^^^^^^^
error: aborting due to previous error |
This comment has been minimized.
This comment has been minimized.
thedodd
commented
Nov 12, 2018
•
|
I've been running into an issue using this feature. The particular crate which I would like to use this feature for is https://github.com/thedodd/wither. The crate uses the stable channel. I've been attempting to switch this feature on using the following pattern: #![cfg_attr(feature="docinclude", feature(external_doc))]
#![cfg_attr(feature="docinclude", doc(include="target-docs.md"))]NOTE: edited to correct a typo. Accidentally pluralized And then I simply invoke It does work as expected if I remove the Thoughts? |
This comment has been minimized.
This comment has been minimized.
|
I was just able to get it working with the following, running #![cfg_attr(feature="docinclude", feature(external_doc))]
#![cfg_attr(feature="docinclude", doc(include="asdf.md"))]It's worth noting that the feature gate is |
This comment has been minimized.
This comment has been minimized.
thedodd
commented
Nov 12, 2018
|
@QuietMisdreavus sorry, I noticed my typo of Well, that's quite strange. I will keep hacking on it and see if I can get it to work. Thanks for the feedback. |
This comment has been minimized.
This comment has been minimized.
thedodd
commented
Nov 12, 2018
|
@QuietMisdreavus so, after hacking on this a bit more, it appears as though I can compile the following code on stable (this time, exact copy-paste): lib.rs #![cfg_attr(feature="docinclude", feature(external_doc))]
#![cfg_attr(feature="docinclude", doc(include("../../README.md")))]
# ... snip
[features]
docinclude = [] # Used only for activating `doc(include="...")` on stable.
[package.metadata.docs.rs]
features = ["docinclude"] # Activate `docinclude` during docs.rs build.The command I run: Cargo version:
Rustc version:
The end result is that the build goes through, but still no included docs. Running the same exact thing, but with a nightly compiler, yields the same result. Successful build, but no docs. |
This comment has been minimized.
This comment has been minimized.
|
@thedodd it's |
This comment has been minimized.
This comment has been minimized.
thedodd
commented
Nov 12, 2018
|
So, another pertinent bit of information is that this repo is a workspace with two crates, However, once again, the docs do not appear when running from the crate specific directory (as opposed to workspace dir) in any of the cases mentioned above. I've For reference sake, I have pushed a branch called |
This comment has been minimized.
This comment has been minimized.
thedodd
commented
Nov 12, 2018
|
@ollie27 you may have just saved my life ... testing that out now. |
This comment has been minimized.
This comment has been minimized.
thedodd
commented
Nov 12, 2018
•
|
@ollie27 thanks for being the greatest human alive right now. It's always the small things. Thanks for clearing that up for me. I must have edited the attribute at one point while I was setting up the |
This comment has been minimized.
This comment has been minimized.
JeanMertz
commented
Nov 14, 2018
I wanted to quickly note that I too love this feature. I like to document my libraries as much as is required to make them easy to use by anyone interested. But obviously, I dislike having outdated docs no longer reflect the reality of the code. This works really well when using documentation examples that get automatically added to the test suite. One downside to this approach is that if you want to make your doctests also remain readable/understandable, you end up duplicating your tests many times, each time commenting out a different part of the test, to only show the part that is relevant to the reader of your documentation. (side note: it would be nice if you could designate a block as "include this in all other code blocks in this documentation section", but I can see how that can get pretty complicated at some point, and perhaps even reduce readability of the unrendered documentation) I am glad we have this capability in Rust, but the downside is that inline code documentation can become extremely long (hundreds of lines for a single trait method happens), which breaks my flow when reading the code. Ideally, I'd want to only see a short description of the method in the code, but have a more robust example and description in the documentation. This feature lets me do exactly that You can see a small example here: rustic-games/things@ae5280d I plan on using this a lot from now on. The about the bad line number info: yeah, I too noticed this while debugging an example that was failing. It was not a big deal, but it does give you a short pause, before you realise what's going on |
This comment has been minimized.
This comment has been minimized.
|
I have a branch pending that improves the diagnostics for this feature, but it's based on #56258, so I'm going to let that PR get merged before opening another PR. |
added a commit
to pietroalbini/rust
that referenced
this issue
Dec 11, 2018
added a commit
to kennytm/rust
that referenced
this issue
Dec 12, 2018
added a commit
to pietroalbini/rust
that referenced
this issue
Dec 12, 2018
added a commit
to pietroalbini/rust
that referenced
this issue
Dec 13, 2018
added a commit
to kennytm/rust
that referenced
this issue
Dec 13, 2018
added a commit
to kennytm/rust
that referenced
this issue
Dec 14, 2018
added a commit
to kennytm/rust
that referenced
this issue
Dec 14, 2018
added a commit
to pietroalbini/rust
that referenced
this issue
Dec 14, 2018
added a commit
to pietroalbini/rust
that referenced
this issue
Dec 15, 2018
This comment has been minimized.
This comment has been minimized.
|
It seems like a really underpromoted possibility of this feature (though it obviously hasn't gone unnoticed) is the ability to have your README automatically doctested. I think on that basis alone it should be possible to generate a lot of interest and engineering effort toward getting this working well and stabilized. |
This comment has been minimized.
This comment has been minimized.
|
I've got a proof-of-concept project for using this feature to test code examples in README.md: https://github.com/abonander/readme-doctest-poc I chose to apply the attribute to a private typedef since no code gets generated for those. Fixing the file/line numbers for test failures in included files is definitely important though; I can see it being a real pain trying to fix failures if you have a lot of examples (it's not exactly common to add a lot of context to asserts in examples since they're usually self-evident). |
This comment has been minimized.
This comment has been minimized.
|
Another thought: this would be significantly cooler if the Rustdoc CSS had a class that hides its contents so you could just reuse your README as your crate root docs and just hide stuff that doesn't necessarily need to be in the docs like license information or contributing instructions or CI build status. That use-case is unfortunately a non-starter for most while this feature is unstable anyway. I don't want to require nightly to build documentation (or just sometimes not have crate root docs). |
This comment has been minimized.
This comment has been minimized.
|
@abonander the way I've usually gone about this is to use |
This comment has been minimized.
This comment has been minimized.
|
The paths being relative to the root module's file still seems like the wrong choice to me (at least for the use-cases I have). @yoshuawuyts and @SimonSapin appear to agree and @mgattozzi's last comment seems to be ok with changing it (and I haven't seen any other opinions noted since implementation). Is there any chance of re-discussing this now that there's some usage data to base it off? |
This comment has been minimized.
This comment has been minimized.
|
I'm sure @QuietMisdreavus has a more informed opinion of this now then I would regarding this. I'm of the opinion of the least amount of surprise meaning consistency with what Rust has done before, whether it's relative to the file or the crate root (I'm not sure which it is tbh). |
This comment has been minimized.
This comment has been minimized.
|
What Rust has done before is that the |
This comment has been minimized.
This comment has been minimized.
|
I have the same opinion about source file directories as in my comment from last year:
|
nrc commentedSep 21, 2017
•
edited by QuietMisdreavus
RFC PR: rust-lang/rfcs#1990
RFC text: https://github.com/rust-lang/rfcs/blob/master/text/1990-external-doc-attribute.md
Current documentation
Summary of how to use this:
#![feature(external_doc)]to your crate."src/some-docs.md"with some docs to your crate.#[doc(include = "some-docs.md")]to something that needs some docs. The file path is relative tolib.rs, so if you want adocfolder to live alongsidesrc, then all your paths inside thedoc(include)attributes need to begin with../doc.Summary of current status:
Current tasks:
(promote the "failed to load file" warnings to proper lints?)(Make them hard errors instead, per the RFC #46858)