-
-
Notifications
You must be signed in to change notification settings - Fork 107
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
doc_cfg
hints not shown on reexports from private modules
#1079
Comments
To illustrate this issue differently I have minimal reproducible example, including comments explaining the situation: #![feature(doc_cfg)]
#[doc(cfg(feature = "foobar"))]
pub mod imp_pub {
/// Feature on `struct` in public module shows, despite no `doc_cfg` directly on the `struct`
pub struct BarPub {}
}
// This only shows Re-exports, but doesn't place the type in the top-level module
#[doc(cfg(feature = "foobar"))]
pub use crate::imp_pub::*;
#[doc(cfg(feature = "foobar"))]
mod imp_priv {
/// Feature on `struct` in private module is never shown
pub struct BarPriv {}
impl BarPriv {
/// Oddly enough the feature guard _is_ shown here
pub fn test() {}
}
}
#[doc(cfg(feature = "foobar"))]
pub use crate::imp_priv::*;
#[doc(cfg(feature = "foobar"))]
mod imp_priv_2 {
/// In a private module `doc_cfg` has to be placed directly on the `struct`
#[doc(cfg(feature = "foobar"))]
pub struct Bar {}
impl Bar {
/// The explicit feature guard is hidden here because it is _implied_ from the surrounding [`Bar`] type
#[doc(cfg(feature = "foobar"))]
pub fn test() {}
}
}
#[doc(cfg(feature = "foobar"))]
pub use crate::imp_priv_2::*; This shows: And: But we really want |
Well first of all: this is awesome! Thanks a lot for doing this! My main question now is: will rustdoc remove this feature before that this one gets merged or not? Well, I suppose not. For reference, here is the work in progress to remove the need for For the combination of the attributes, I'm surprised that rustdoc doesn't handle it. I think it'd be better to open an issue there so it doesn't get lost as you suggested. But beyond that, I'm curious of the actual code. Don't have much suggestions for the moment but the end result definitely looks great. |
Thanks! Actually I have to thank you for working on
You mean implying
I'll make a new issue based on the info above.
There's no actual code yet, nor should there be. The third point ( |
Considering that |
Since it has been a nightly feature that tradeoff must have already been made when its use was introduced here. End-users are probably well aware that they have to build the docs with nightly anyhow? Are users doing that anyway or simply compiling their own programs without Anyway, that's nothing that this issue nor the PR changes. |
I think that's the important part here. We already require nightly for building the docs anyway, this PR does not make the situation worse in that regard AFAIU. I don't like that we require nightly for building the docs, but that was introduced a few weeks ago already. |
Correct - if anything there are now less |
Hi @GuillaumeGomez! I am currently revisiting the idea to omit
cfg
/doc_cfg
attributes when the parent (impl
block ormod
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 onmod
s andfn
s, not onstruct
s in ie.glib::wrapper!
. As it seemsrustdoc
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 examplegdk::DeviceTool
. Onmaster
it has a feature constraint on themod
andfn
s, and looks like this (with the followingrustc
nightly):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 thefn
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 thefn
s but do not show in the docs, to illustrate that they are coalesced into the requirement on thestruct
as a whole 🥳In closing:
#[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;doc(cfg)
directly on the type (ie. insideglib::wrapper!
) to get the desired result in the third and fourth picture.What do you think?
The text was updated successfully, but these errors were encountered: