Skip to content

Doc comments only apply to the first #[cfg] item, even if another is ultimately selected. #91147

Closed
@umanwizard

Description

@umanwizard

Given the following code:

#![warn(missing_docs)]
//! my test crate

/// foo.
#[cfg(debug_assertions)]
pub const FOO: () = ();
#[cfg(not(debug_assertions))]
pub const FOO: () = ();

fn main() {}

The current output is:

warning: missing documentation for a constant
 --> src/main.rs:8:1
  |
8 | pub const FOO: () = ();
  | ^^^^^^^^^^^^^^^^^^^^^^^
  |
note: the lint level is defined here
 --> src/main.rs:1:9
  |
1 | #![warn(missing_docs)]
  |         ^^^^^^^^^^^^

warning: `test_rust` (bin "test_rust") generated 1 warning
    Finished release [optimized] target(s) in 0.00s

The above is only seen on release builds; on debug builds, no warning is output.

The doc comment should apply to whichever piece of code is actually compiled. Is there a way to achieve this without duplicating the comment?

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-discussionCategory: Discussion or questions that doesn't represent real issues.T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions