Skip to content

Commit ec3a6b4

Browse files
authored
Rollup merge of #155230 - TaKO8Ki:fix-unused-features-doc-cfg, r=Kivooeo
Avoid linting `doc_cfg` as unused in rustc Fixes #154487 https://github.com/rust-lang/rust/blob/af80b0f2cd0505bcc86eaa675d1ab403110d373a/src/librustdoc/passes/propagate_doc_cfg.rs#L19-L26
2 parents 803a722 + 5c80d90 commit ec3a6b4

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

compiler/rustc_middle/src/ty/context.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ use rustc_session::config::CrateType;
4444
use rustc_session::cstore::{CrateStoreDyn, Untracked};
4545
use rustc_session::lint::Lint;
4646
use rustc_span::def_id::{CRATE_DEF_ID, DefPathHash, StableCrateId};
47-
use rustc_span::{DUMMY_SP, Ident, Span, Symbol, kw};
47+
use rustc_span::{DUMMY_SP, Ident, Span, Symbol, kw, sym};
4848
use rustc_type_ir::TyKind::*;
4949
pub use rustc_type_ir::lift::Lift;
5050
use rustc_type_ir::{CollectAndApply, TypeFlags, WithCachedTypeInfo, elaborate, search_graph};
@@ -1705,6 +1705,10 @@ impl<'tcx> TyCtxt<'tcx> {
17051705
// in downstream crates. It should never be linted, but should we
17061706
// hack this in the linter to ignore it?
17071707
&& f.as_str() != "restricted_std"
1708+
// `doc_cfg` affects rustdoc behavior: rustdoc checks it via
1709+
// `tcx.features().doc_cfg()`, but a normal rustc compilation may
1710+
// never observe that use. Do not lint it as unused here.
1711+
&& *f != sym::doc_cfg
17081712
})
17091713
.collect::<Vec<_>>();
17101714

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
//@ check-pass
2+
//@ compile-flags: --check-cfg=cfg(feature,values("enabled_feature"))
3+
// Regression test for https://github.com/rust-lang/rust/issues/154487
4+
5+
#![crate_type = "lib"]
6+
#![deny(unused_features)]
7+
#![feature(doc_cfg)]
8+
9+
#[cfg(feature = "enabled_feature")]
10+
pub fn foo() {}

0 commit comments

Comments
 (0)