Skip to content

unused_features false positive on doc_cfg #154487

@kpreid

Description

@kpreid

Code

#![feature(doc_cfg)]

#[cfg(feature = "enabled_feature")]
pub fn foo() {}

Current output

warning: feature `doc_cfg` is declared but not used
 --> src/lib.rs:1:12
  |
1 | #![feature(doc_cfg)]
  |            ^^^^^^^
  |
  = note: `#[warn(unused_features)]` (part of `#[warn(unused)]`) on by default

warning: `scratchpad` (lib) generated 1 warning

Desired output

No warning

Rationale and extra context

The feature modifies rustdoc output regardless of whether #[doc(cfg)] is explicitly used in the source code, so it is not unused.

Rust Version

rustc 1.96.0-nightly (fda6d37bb 2026-03-27)
binary: rustc
commit-hash: fda6d37bb88ee12fd50fa54d15859f1f91b74f55
commit-date: 2026-03-27
host: aarch64-apple-darwin
release: 1.96.0-nightly
LLVM version: 22.1.2

Anything else?

@rustbot label +F-doc_cfg

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsF-doc_cfg`#![feature(doc_cfg)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions