-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
set cfg(rustdoc) when rustdoc is running on a crate #53076
Conversation
I'll bring this up at core team triage next week if I don't forget. |
Awesome! |
SGTM. Also note that tools attributes are nearly stable (just waiting for a PR), so you can now use attributes of the form |
cc @rust-lang/lang -- this PR is adding a |
We discussed this in Core team triage and the conclusion was to cc the lang team; we felt it wasn't really our field of purview at this point. |
I've added |
This makes me a little nervous, but given that people can trivially do this themselves anyway, we might as well provide a sanctioned solution. That said...I wonder if rustdoc could somehow handle platform-specific things more automatically, rather than requiring people to use |
@joshtriplett You have just described the oldest rustdoc issue on this tracker. The biggest problem with "making rustdoc see through cfg" is that rustdoc isn't the one that's processing them. Rustc is. Rustdoc will happily try to show off everything that's given to it, if rustc can handle ignoring every |
@QuietMisdreavus Ah, I see. I didn't realize that, I thought this fell under the domain of rustdoc rather than rustc. |
Seems fine to me; especially since it is feature gated. :) |
Chatted with @QuietMisdreavus about this at RustConf, and it seems reasonable. I'm going to go ahead and FCP this and see if anyone objects. @rfcbot merge |
Team member @joshtriplett has proposed to merge this. The next step is review by the rest of the tagged teams:
No concerns currently listed. Once a majority of reviewers approve (and none object), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
b19428b
to
23d87fe
Compare
This is fine for me guys, maybe we can also set up a |
@onur That should be fairly easy to set up, since you can add cfg flags via the command-line. We'd just need to add |
🔔 This is now entering its final comment period, as per the review above. 🔔 |
Note: for this issue, I think it's appropriate to just treat the rfcbot coordination above as a poll for consensus, rather than seeking "FCP" specifically; I think the rustdoc team can simply proceed with this change at their discretion at this point. |
src/librustdoc/lib.rs
Outdated
@@ -645,7 +645,7 @@ where R: 'static + Send, | |||
paths.add_path(s, ErrorOutputType::default()); | |||
} | |||
let mut cfgs = matches.opt_strs("cfg"); | |||
cfgs.push("rustdoc"); | |||
cfgs.push("rustdoc".to_string()); |
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.
Can you please squash this into the patch that introduced these lines?
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.
Done!
23d87fe
to
ad2169c
Compare
Since everyone agreed, let's get it in then. Thanks @QuietMisdreavus! @bors: r+ |
📌 Commit ad2169c has been approved by |
…laumeGomez set cfg(rustdoc) when rustdoc is running on a crate When using `#[doc(cfg)]` to document platform-specific items, it's a little cumbersome to get all the platforms' items to appear all at once. For example, the standard library adds `--cfg dox` to rustdoc's command line whenever it builds docs, and the documentation for `#![feature(doc_cfg)]` suggests using a Cargo feature to approximate the same thing. This is a little awkward, because you always need to remember to set `--features dox` whenever you build documentation. This PR proposes making rustdoc set `#[cfg(rustdoc)]` whenever it runs on a crate, to provide an officially-sanctioned version of this that is set automatically. This way, there's a standardized way to declare that a certain version of an item is specifically when building docs. To try to prevent the spread of this feature from happening too quickly, this PR also restricts the use of this flag to whenever `#![feature(doc_cfg)]` is active. I'm sure there are other uses for this, but right now i'm tying it to this feature. (If it makes more sense to give this its own feature, i can easily do that.)
Rollup of 9 pull requests Successful merges: - #53076 (set cfg(rustdoc) when rustdoc is running on a crate) - #53622 (cleanup: Add main functions to some UI tests) - #53769 (Also link Clippy repo in the CONTRIBUTING.md file) - #53774 (Add rust-gdbgui script.) - #53781 (bench: libcore: fix build failure of any.rs benchmark (use "dyn Any")) - #53782 (Make Arc cloning mechanics clearer in module docs) - #53790 (Add regression test for issue #52060) - #53801 (Prevent duplicated impl on foreign types) - #53850 (Nuke the `const_to_allocation` query)
This was added in rust-lang#53076 because several dependencies were using `cfg(dox)` instead of `cfg(rustdoc)`. I ran `rg 'cfg\(dox\)'` on the source tree with no matches, so I think this is now safe to remove.
Remove --cfg dox from rustdoc.rs This was added in rust-lang#53076 because several dependencies were using `cfg(dox)` instead of `cfg(rustdoc)` (now `cfg(doc)`). I ran `rg 'cfg\(dox\)'` on the source tree with no matches, so I think this is now safe to remove. r? @Mark-Simulacrum cc @QuietMisdreavus :)
Remove --cfg dox from rustdoc.rs This was added in rust-lang#53076 because several dependencies were using `cfg(dox)` instead of `cfg(rustdoc)` (now `cfg(doc)`). I ran `rg 'cfg\(dox\)'` on the source tree with no matches, so I think this is now safe to remove. r? `@Mark-Simulacrum` cc `@QuietMisdreavus` :)
When using
#[doc(cfg)]
to document platform-specific items, it's a little cumbersome to get all the platforms' items to appear all at once. For example, the standard library adds--cfg dox
to rustdoc's command line whenever it builds docs, and the documentation for#![feature(doc_cfg)]
suggests using a Cargo feature to approximate the same thing. This is a little awkward, because you always need to remember to set--features dox
whenever you build documentation.This PR proposes making rustdoc set
#[cfg(rustdoc)]
whenever it runs on a crate, to provide an officially-sanctioned version of this that is set automatically. This way, there's a standardized way to declare that a certain version of an item is specifically when building docs.To try to prevent the spread of this feature from happening too quickly, this PR also restricts the use of this flag to whenever
#![feature(doc_cfg)]
is active. I'm sure there are other uses for this, but right now i'm tying it to this feature. (If it makes more sense to give this its own feature, i can easily do that.)r? @rust-lang/rustdoc (and maaaaaaybe someone from core? This seems a bit far-reaching...)