-
-
Notifications
You must be signed in to change notification settings - Fork 111
Description
Hi @GuillaumeGomez! I am currently revisiting the idea to omit cfg
/doc_cfg
attributes when the parent (impl
block or mod
in its entirety) already has a version constraint that is at least as strict. This was sparked after going through https://doc.rust-lang.org/std/os/index.html, where modules and types do not have #[doc(cfg(unix))]
but seem to inherit the constraint from their parent module, solving exactly the issue you were describing.
In other words, we have version information on the module, any modules within it, and any struct
/trait
that has its own page (right at the top, and on the module overview page) - without recursively duplicating #[doc(cfg())]
etc 🥳
I have hence rebased those commits back and regenerated, and, to no surprise, the features are indeed propagated into the files/modules... but not in the way I expected.
"Fortunately" the same issue seems to be affecting master
already. doc(cfg)
is currently only used on mod
s and fn
s, not on struct
s in ie. glib::wrapper!
. As it seems rustdoc
is not able to put these feature requirement labels on items in a private module (mod auto;
) that are then re-exported (pub use auto::*;
) - even if the same version constraint is on both. Let's take for example gdk::DeviceTool
. On master
it has a feature constraint on the mod
and fn
s, and looks like this (with the following rustc
nightly):
me:gtk-rs/ $ rustc +nightly -Vv
rustc 1.53.0-nightly (5d04957a4 2021-03-22)
binary: rustc
commit-hash: 5d04957a4b4714f71d38326fc96a0b0ef6dc5800
commit-date: 2021-03-22
host: x86_64-unknown-linux-gnu
release: 1.53.0-nightly
LLVM version: 12.0.0
There's no version constraint on the module overview page:
On the page for that type, there is no feature requirement on the struct
, but there is on the fn
s:
Nothing changes after regenerating with the commits linked above. All superfluous #[cfg]
and #[doc(cfg())]
are now gone making the code a little more readable, though.
However, if the constraint is added to the struct
directly we finally get what we want:
Note that #[doc(cfg)]
has been added back to the fn
s but do not show in the docs, to illustrate that they are coalesced into the requirement on the struct
as a whole 🥳
In closing:
- I should submit the above commits. They do not improve the documentation situation, but do make the code a little more readable with all the duplicate
#[cfg]
's gone; -
Create an issue about this on the rust tracker.rustdoc:doc_cfg
hints not shown on reexports from private modules rust-lang/rust#83428: It seems likerustdoc
needs to learn how to combine the#[doc(cfg)]
of the module and the reexport? I could not find any open issue for this but there are too many to check them all; - Temporary: emit
doc(cfg)
directly on the type (ie. insideglib::wrapper!
) to get the desired result in the third and fourth picture.
What do you think?