Skip to content
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

Tracking issue for #[doc(cfg(…))], #[doc(cfg_hide(…))] and doc_auto_cfg #43781

Open
3 of 5 tasks
kennytm opened this issue Aug 10, 2017 · 108 comments
Open
3 of 5 tasks
Labels
B-unstable Blocker: Implemented in the nightly compiler and unstable. C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. F-doc_auto_cfg `#![feature(doc_auto_cfg)]` F-doc_cfg `#![feature(doc_cfg)]` T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@kennytm
Copy link
Member

kennytm commented Aug 10, 2017

This is a tracking issue for the #[doc(cfg(…))] attribute (feature: doc_cfg) introduced in #43348 and #[doc(cfg_hide(…))] (feature: doc_cfg_hide) attribute introduced in #89596, along with the doc_auto_cfg feature introduced in #90502.

Steps:

(cc #1998)

@Mark-Simulacrum Mark-Simulacrum added C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. T-dev-tools Relevant to the dev-tools subteam, which will review and decide on the PR/issue. labels Aug 10, 2017
@kennytm kennytm added T-dev-tools-rustdoc and removed T-dev-tools Relevant to the dev-tools subteam, which will review and decide on the PR/issue. labels Oct 21, 2017
fengalin added a commit to fengalin/gstreamer-rs that referenced this issue Mar 17, 2018
There are different implementations and signatures for `get_pollfd` depending
on whether the target plateform is unix or windows. When generating the doc,
we need both implementations to appear regardless of the target platform. This
commit is inspired by the way Rust `std` library deals with `process::Command`
OS dependent variants
(https://doc.rust-lang.org/std/process/struct.Command.html#impl-CommandExt).

Documentation can't be accurate though as we can't use the`std::os::windows`
on `unix` and vice versa. As a workaround a fake fd class matching the other
platform is declared.

This could be further enhanced once `#[doc(cfg(...))]` is stabilized
(rust-lang/rust#43781) by declaring `#[doc(cfg(unix))]`
or `#[doc(cfg(windows))]` instead of the hard coded comments `This is supported
on **Windows/Unix** only`. Unfortunately, these comments disappear when
generating will `--all-features` because they are not part of the documentation
in the gir file.
fengalin added a commit to fengalin/gstreamer-rs that referenced this issue Mar 17, 2018
There are different implementations and signatures for `get_pollfd` depending
on whether the target platform is unix or windows. When generating the doc,
we need both implementations to appear regardless of the target platform. This
commit is inspired by the way Rust `std` library deals with `process::Command`
OS dependent variants
(https://doc.rust-lang.org/std/process/struct.Command.html#impl-CommandExt).

Documentation can't be accurate though as we can't use the`std::os::windows`
on `unix` and vice versa. As a workaround a fake fd class matching the other
platform is declared.

This could be further enhanced once `#[doc(cfg(...))]` is stabilized
(rust-lang/rust#43781) by declaring `#[doc(cfg(unix))]`
or `#[doc(cfg(windows))]` instead of the hard coded comments `This is supported
on **Windows/Unix** only`. Unfortunately, these comments disappear when
generating will `--all-features` because they are not part of the documentation
in the gir file.
fengalin added a commit to fengalin/gstreamer-rs that referenced this issue Mar 18, 2018
There are different implementations and signatures for `get_pollfd` depending
on whether the target platform is unix or windows. When generating the doc,
we need both implementations to appear regardless of the target platform. This
commit is inspired by the way Rust `std` library deals with `process::Command`
OS dependent variants
(https://doc.rust-lang.org/std/process/struct.Command.html#impl-CommandExt).

Documentation can't be accurate though as we can't use the`std::os::windows`
on `unix` and vice versa. As a workaround a fake fd class matching the other
platform is declared.

This could be further enhanced once `#[doc(cfg(...))]` is stabilized
(rust-lang/rust#43781) by declaring `#[doc(cfg(unix))]`
or `#[doc(cfg(windows))]` instead of the hard coded comments `This is supported
on **Windows/Unix** only`. Unfortunately, these comments disappear when
generating will `--all-features` because they are not part of the documentation
in the gir file.
fengalin added a commit to fengalin/gstreamer-rs that referenced this issue Mar 19, 2018
There are different implementations and signatures for `get_pollfd` depending
on whether the target platform is unix or windows. When generating the doc,
we need both implementations to appear regardless of the target platform. This
commit is inspired by the way Rust `std` library deals with `process::Command`
OS dependent variants
(https://doc.rust-lang.org/std/process/struct.Command.html#impl-CommandExt).

Documentation can't be accurate though as we can't use the`std::os::windows`
on `unix` and vice versa. As a workaround a fake fd class matching the other
platform is declared.

This could be further enhanced once `#[doc(cfg(...))]` is stabilized
(rust-lang/rust#43781) by declaring `#[doc(cfg(unix))]`
or `#[doc(cfg(windows))]` instead of the hard coded comments `This is supported
on **Windows/Unix** only`. Unfortunately, these comments disappear when
generating will `--all-features` because they are not part of the documentation
in the gir file.
sdroege pushed a commit to sdroege/gstreamer-rs that referenced this issue Mar 19, 2018
There are different implementations and signatures for `get_pollfd` depending
on whether the target platform is unix or windows. When generating the doc,
we need both implementations to appear regardless of the target platform. This
commit is inspired by the way Rust `std` library deals with `process::Command`
OS dependent variants
(https://doc.rust-lang.org/std/process/struct.Command.html#impl-CommandExt).

Documentation can't be accurate though as we can't use the`std::os::windows`
on `unix` and vice versa. As a workaround a fake fd class matching the other
platform is declared.

This could be further enhanced once `#[doc(cfg(...))]` is stabilized
(rust-lang/rust#43781) by declaring `#[doc(cfg(unix))]`
or `#[doc(cfg(windows))]` instead of the hard coded comments `This is supported
on **Windows/Unix** only`. Unfortunately, these comments disappear when
generating will `--all-features` because they are not part of the documentation
in the gir file.
@QuietMisdreavus QuietMisdreavus added T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. and removed T-rustdoc labels May 15, 2018
charlie-ht pushed a commit to charlie-ht/gstreamer-rs that referenced this issue Oct 28, 2018
There are different implementations and signatures for `get_pollfd` depending
on whether the target platform is unix or windows. When generating the doc,
we need both implementations to appear regardless of the target platform. This
commit is inspired by the way Rust `std` library deals with `process::Command`
OS dependent variants
(https://doc.rust-lang.org/std/process/struct.Command.html#impl-CommandExt).

Documentation can't be accurate though as we can't use the`std::os::windows`
on `unix` and vice versa. As a workaround a fake fd class matching the other
platform is declared.

This could be further enhanced once `#[doc(cfg(...))]` is stabilized
(rust-lang/rust#43781) by declaring `#[doc(cfg(unix))]`
or `#[doc(cfg(windows))]` instead of the hard coded comments `This is supported
on **Windows/Unix** only`. Unfortunately, these comments disappear when
generating will `--all-features` because they are not part of the documentation
in the gir file.
@sfackler
Copy link
Member

sfackler commented Jan 7, 2019

#[cfg(rustdoc)] is also gated on this issue but seems distinct (and less risky). Could we FCP that portion in particular?

asomers added a commit to asomers/futures-locks that referenced this issue Jan 30, 2019
asomers added a commit to asomers/futures-locks that referenced this issue Jan 30, 2019
asomers added a commit to asomers/futures-locks that referenced this issue Jan 30, 2019
@asomers
Copy link
Contributor

asomers commented Jan 30, 2019

I think that #[cfg(rustdoc)], when applied to structs, should automatically skip any non-public members. That would greatly reduce the amount of extra typing required by crates like Nix.

@Nemo157
Copy link
Member

Nemo157 commented Jul 4, 2019

I was just trying this out for documenting crate features, it "works" but if this is a potential usecase it would be nice to special case the rendering for it:


Screenshot 2019-07-04 at 12 35 06


Screenshot 2019-07-04 at 12 35 27

@Nemo157
Copy link
Member

Nemo157 commented Jul 4, 2019

There is also the issue that it repeats every feature on every item in a page:

Screenshot 2019-07-04 at 14 17 45

When I last attempted to do something about rendering features I found it much more useful to separately keep track of "all required features" to render at the top of the items page and "newly introduced features" to render on the sub-items on the page, so you don't get this distracting repetition on every item.

@dtolnay
Copy link
Member

dtolnay commented Dec 25, 2019

We tried out this feature in Syn (dtolnay/syn#734) and decided against using it yet.


What I am happy with

I like how the message turns out at the top of the doc page of a single type or function.

We had previously displayed this information using an italicized note, which was less noticeable.


What I am not happy with

Our index page becomes extremely noisy. I wish there were a way to not show all of these in our case. It is enough to have this information on the type's individual page. Cfg combinations are not among the most important information to show on the index page.

Also inheriting the same note onto every public field seems unnecessary in our use case.

artob added a commit to asimov-platform/protoflow that referenced this issue Aug 19, 2024
@clarfonthey
Copy link
Contributor

Just poking around: it appears that the doc_auto_cfg feature links here, but there's no docs in the unstable book for it and the feature doesn't seem to match what's proposed in the RFC. Is this just not implemented, or is the syntax different and this just isn't documented?

@GuillaumeGomez
Copy link
Member

The RFC (which is still under discussion so maybe not its final form) proposes something slightly different than what's currently implemented and adds more attributes to give more control.

Currently, to enable this feature, you use #![doc(auto_cfg)] and that's it.

@jmillikin
Copy link
Contributor

Two years ago on #100883 I asked about the possibility of stabilizing #[doc(cfg(...)) without #[doc(auto_cfg)] on the principle that the former seems to be well-understood, while the latter is a more complex feature that has ongoing discussion about how exactly it should work.

At the time, the response was that stabilizing #[doc(cfg(...))] by itself wouldn't provide a good user experience, and that there would potentially be ecosystem churn from people adding it all over and then removing it once #[doc(auto_cfg)] was ready.

But ... it's been two years, and neither is stabilized. I could have been using #[doc(cfg(...)] all this time. It's pretty frustrating to have a ready-to-stabilize feature I want be blocked on a vaguely-related feature that I don't particularly care about.

Can #[doc(cfg(...))] please be stabilized? Feel free to put some verbiage in the release notes like "if you're planning to use #[doc(auto_cfg)] in the future then please hold on until that arrives" if there's still a concern about ecosystem churn.

@jhpratt
Copy link
Member

jhpratt commented Oct 17, 2024

@jmillikin This needs an RFC to be stabilized. That's currently awaiting FCP (it needs 3 more checkboxes): rust-lang/rfcs#3631 (comment)

@jmillikin
Copy link
Contributor

I understand why #[doc(auto_cfg)] needs an RFC.

Why would #[doc(cfg(...))] need an RFC?

@jhpratt
Copy link
Member

jhpratt commented Oct 17, 2024

It's a new, non-trivial language feature. They don't get added on a whim; there's a process to follow.

@clarfonthey
Copy link
Contributor

While it feels like one feature may be easier to stabilise, I can't imagine that filing a shorter RFC just for doc(cfg(...)) will go any faster. Plus, once the RFC for both features is added, I think it would be reasonable to stabilise just that feature since it doesn't really need any more work done.

So, I get the impatience, just, this is pretty much all volunteer work, so, it's gonna take a while for folks to set aside the time to review everything and sign off on it.

@theemathas
Copy link
Contributor

For reference, writing the following at the top of lib.rs will make feature-gated stuff documented properly on docs.rs, while still having your program compiling in stable rust:

#![cfg_attr(docsrs, feature(doc_auto_cfg))]

RoloEdits added a commit to Webtoon-Studio/webtoon that referenced this issue Oct 25, 2024
### [`doc_auto_cfg`: Automatically generate
`#[doc(cfg)]`](https://doc.rust-lang.org/rustdoc/unstable-features.html#doc_auto_cfg-automatically-generate-doccfg)

-   Tracking issue:
[#43781](rust-lang/rust#43781)

`doc_auto_cfg` is an extension to the `#[doc(cfg)]` feature. With it,
you don't need to add `#[doc(cfg(...)]` anymore unless you want to
override the default behaviour.
RoloEdits added a commit to Webtoon-Studio/webtoon that referenced this issue Oct 25, 2024
### [`doc_auto_cfg`: Automatically generate
`#[doc(cfg)]`](https://doc.rust-lang.org/rustdoc/unstable-features.html#doc_auto_cfg-automatically-generate-doccfg)

-   Tracking issue:
[#43781](rust-lang/rust#43781)

`doc_auto_cfg` is an extension to the `#[doc(cfg)]` feature. With it,
you don't need to add `#[doc(cfg(...)]` anymore unless you want to
override the default behaviour.
@jmillikin
Copy link
Contributor

#[cfg_attr(docsrs), ...] doesn't help for people who are trying to run rustdoc as part of their build and/or CI process, so it would be nice to get support for at least #[doc(cfg(...))] stabilized.

@GuillaumeGomez
Copy link
Member

It's all or nothing. RFC is open and waiting for reviews. Sadly there is nothing more we can do about it.

The cfg_attr trick also works with features. Nothing prevents you do to run your CI in nightly. It's not the best but until the RFC is merged and the feature implemented (this part should be pretty quick), nothing else can be done.

@jmillikin
Copy link
Contributor

I'm sorry, this may be a really dumb question, but why is it "all or nothing"?

I don't understand why #[doc(cfg(...))] can't be stabilized as an MVP, independent of #[doc(auto_cfg)]. They're both already implemented, and from the perspective of writing a stabilization report and/or updating the reference the former feature seems a lot easier to document (since it's entirely explicit annotations by the author).

@jhpratt
Copy link
Member

jhpratt commented Oct 25, 2024

Theoretically it could be done separately, but it wouldn't be done any faster (which seems to be what you truly want). There is nothing that can be done to speed up stabilization (at least that's within the code of conduct).

@jmillikin
Copy link
Contributor

Theoretically it could be done separately, but it wouldn't be done any faster (which seems to be what you truly want). There is nothing that can be done to speed up stabilization (at least that's within the code of conduct).

I've frequently seen subsets of a complex feature stabilize separately, most famously the various parts of async stabilizing as the design was iterated on. I've also seen existing RFCs get split up into an MVP and a follow-on with more complexity but better ergonomics.

It could be that there's some aspect of how #[doc(cfg(...))] and #[doc(auto_cfg)] interact that I'm missing due to lack of rustc internals knowledge, but from an outside perspective it's not obvious why #[doc(cfg(....))] couldn't be split off and stabilized by itself (e.g. in 1.85 or 1.86), and then #[doc(auto_cfg))] can stabilize on its own timeframe (presumably >= 1.90).

@jhpratt
Copy link
Member

jhpratt commented Oct 25, 2024

Note that when features are split up it's generally because there are concerns, unresolved questions, or simply too much work to do all at once. None of that applies here. The only blocker (pending concerns being raised) is checkboxes.

@GuillaumeGomez
Copy link
Member

In addition to what @jhpratt said: because it would need to go through an RFC, which means asking people to write another RFC and yet other people to review it. We have limited bandwidth and most contributors are not paid to do so and we're also facing a huge burn-out issue across the project as well so it wouldn't help in this regard either.

@madsmtm
Copy link
Contributor

madsmtm commented Oct 25, 2024

I've pinged the people that the FCP is waiting for (no flak intended towards any of these wonderful people), hopefully that can speed up the progress a little bit.

@GuillaumeGomez
Copy link
Member

  1. Please don't.
  2. Likely not.

@madsmtm
Copy link
Contributor

madsmtm commented Oct 25, 2024

Apologies then.

@SpriteOvO
Copy link
Contributor

SpriteOvO commented Oct 25, 2024

#[cfg_attr(docsrs), ...] doesn't help for people who are trying to run rustdoc as part of their build and/or CI process

@jmillikin This is the solution I have been using.

Cargo.toml

[package.metadata.docs.rs]
all-features = true

[build-dependencies]
rustc_version = "0.4.1"

build.rs

use rustc_version::{version_meta, Channel};

fn main() {
    // Set cfg flags depending on release channel
    let channel = match version_meta().unwrap().channel {
        Channel::Stable => "CHANNEL_STABLE",
        Channel::Beta => "CHANNEL_BETA",
        Channel::Nightly => "CHANNEL_NIGHTLY",
        Channel::Dev => "CHANNEL_DEV",
    };
    println!("cargo:rustc-cfg={}", channel)
}

lib.rs

#![cfg_attr(all(doc, CHANNEL_NIGHTLY), feature(doc_auto_cfg))]

Then run nightly in your CI script, doc_auto_cfg will only be enabled when using nightly toolchain. So this works very well with CI and docs.rs and doesn't affect library users.

@fjarri
Copy link

fjarri commented Oct 25, 2024

The way I have it set up:

Cargo.toml:

[package.metadata.docs.rs]
all-features = true
rustdoc-args = ["--cfg", "docsrs"]

lib.rs:

#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]

CI (mimicking docs.rs settings), with the nightly toolchain:

env RUSTDOCFLAGS='--cfg docsrs -D warnings' cargo doc --all-features

@jmillikin, does that not solve your problem?

m4tx added a commit to flareon-rs/flareon that referenced this issue Nov 21, 2024
See rust-lang/rust#43781. This enables infoboxes like
"Available on crate feature XXX only." in the documentation generated
using `cargo doc` on nightly, or by building on docs.rs.

This can be tested with:

```shell
RUSTDOCFLAGS="--cfg docsrs" cargo +nightly doc --no-deps --all-features
```
m4tx added a commit to flareon-rs/flareon that referenced this issue Nov 22, 2024
See rust-lang/rust#43781. This enables infoboxes like
"Available on crate feature XXX only." in the documentation generated
using `cargo doc` on nightly, or by building on docs.rs.

This can be tested with:

```shell
RUSTDOCFLAGS="--cfg docsrs" cargo +nightly doc --no-deps --all-features
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
B-unstable Blocker: Implemented in the nightly compiler and unstable. C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. F-doc_auto_cfg `#![feature(doc_auto_cfg)]` F-doc_cfg `#![feature(doc_cfg)]` T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
Status: Rejected/Not lang