Rollup merge of #155230 - TaKO8Ki:fix-unused-features-doc-cfg, r=Kivooeo

Avoid linting `doc_cfg` as unused in rustc

Fixes rust-lang/rust#154487

https://github.com/rust-lang/rust/blob/af80b0f2cd0505bcc86eaa675d1ab403110d373a/src/librustdoc/passes/propagate_doc_cfg.rs#L19-L26
This commit is contained in:
Jacob Pratt
2026-04-14 00:37:25 -04:00
committed by GitHub
2 changed files with 15 additions and 1 deletions
+5 -1
View File
@@ -44,7 +44,7 @@
use rustc_session::cstore::{CrateStoreDyn, Untracked};
use rustc_session::lint::Lint;
use rustc_span::def_id::{CRATE_DEF_ID, DefPathHash, StableCrateId};
use rustc_span::{DUMMY_SP, Ident, Span, Symbol, kw};
use rustc_span::{DUMMY_SP, Ident, Span, Symbol, kw, sym};
use rustc_type_ir::TyKind::*;
pub use rustc_type_ir::lift::Lift;
use rustc_type_ir::{CollectAndApply, TypeFlags, WithCachedTypeInfo, elaborate, search_graph};
@@ -1705,6 +1705,10 @@ struct UnusedFeature {
// in downstream crates. It should never be linted, but should we
// hack this in the linter to ignore it?
&& f.as_str() != "restricted_std"
// `doc_cfg` affects rustdoc behavior: rustdoc checks it via
// `tcx.features().doc_cfg()`, but a normal rustc compilation may
// never observe that use. Do not lint it as unused here.
&& *f != sym::doc_cfg
})
.collect::<Vec<_>>();
@@ -0,0 +1,10 @@
//@ check-pass
//@ compile-flags: --check-cfg=cfg(feature,values("enabled_feature"))
// Regression test for https://github.com/rust-lang/rust/issues/154487
#![crate_type = "lib"]
#![deny(unused_features)]
#![feature(doc_cfg)]
#[cfg(feature = "enabled_feature")]
pub fn foo() {}