Skip to content

doc_cfg hints not shown on reexports from private modules #1079

@MarijnS95

Description

@MarijnS95

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 mods and fns, not on structs 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 fns, 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:

image

On the page for that type, there is no feature requirement on the struct, but there is on the fns:

image

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:

image

image

Note that #[doc(cfg)] has been added back to the fns 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 like rustdoc 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. inside glib::wrapper!) to get the desired result in the third and fourth picture.

What do you think?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions