-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Struct field documentation and #[cfg(...)
#45358
Comments
It is working as expected. The doc-comment is only attached to #[deny(missing_docs)]
/// A struct
pub struct Struct {
/// A field
#[cfg(feature = "feature")]
pub field: u32,
/// A field
#[cfg(not(feature = "feature"))]
pub field: u64,
} |
Hmm, that's what I feared.
I encountered this problem in a situation where it's important for the user to know that the field can appear in different versions. Hence, both versions of the documentation need to reference both versions of the field. Which means, I effectively need the same doc comment twice. Probably not a big deal though. Thanks for your reply! |
@hannobraun If all those fields only differ by /// SomeType is u32 when feature is on, and u64 when feature is off.
#[cfg(feature = "feature")]
pub type SomeType = u32;
/// SomeType is u32 when feature is on, and u64 when feature is off.
#[cfg(not(feature = "feature"))]
pub type SomeType = u64;
/// A struct
pub struct Struct {
/// A field
pub field: SomeType,
} |
@kennytm Oh, that's a neat idea! The |
Consider the following code:
I would expect this to compile in any configuration. Only one version of
field
can ever exist. The doc comment should apply to the version offield
that is being compiled.However, if I compile this (without specifying any features), it fails:
If I specify
feature
, it builds without problems:cargo doc
's behavior is consistent with the behavior of the compiler. It only picks up the doc comment, iffeature
is specified (cargo doc --features feature
).This is the nightly version I'm using:
But I'm also seeing this on stable:
Here's a repository with an example Cargo project that can be used to reproduce this problem: https://github.com/hannobraun/field-cfg-doc
The text was updated successfully, but these errors were encountered: