Skip to content

Commit 082accd

Browse files
GuillaumeGomezcuviper
authored andcommitted
Split doc_cfg and doc_auto_cfg features
(cherry picked from commit d50a475)
1 parent 5fd4bb4 commit 082accd

File tree

7 files changed

+28
-5
lines changed

7 files changed

+28
-5
lines changed

compiler/rustc_feature/src/active.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -684,6 +684,9 @@ declare_features! (
684684
/// Allows using the `non_exhaustive_omitted_patterns` lint.
685685
(active, non_exhaustive_omitted_patterns_lint, "1.57.0", Some(89554), None),
686686

687+
/// Tells rustdoc to automatically generate `#[doc(cfg(...))]`.
688+
(active, doc_auto_cfg, "1.57.0", Some(43781), None),
689+
687690
// -------------------------------------------------------------------------
688691
// feature-group-end: actual feature gates
689692
// -------------------------------------------------------------------------

compiler/rustc_span/src/symbol.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,7 @@ symbols! {
549549
div_assign,
550550
doc,
551551
doc_alias,
552+
doc_auto_cfg,
552553
doc_cfg,
553554
doc_cfg_hide,
554555
doc_keyword,

src/librustdoc/clean/types.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -774,6 +774,7 @@ impl AttributesExt for [ast::Attribute] {
774774
fn cfg(&self, tcx: TyCtxt<'_>, hidden_cfg: &FxHashSet<Cfg>) -> Option<Arc<Cfg>> {
775775
let sess = tcx.sess;
776776
let doc_cfg_active = tcx.features().doc_cfg;
777+
let doc_auto_cfg_active = tcx.features().doc_auto_cfg;
777778

778779
fn single<T: IntoIterator>(it: T) -> Option<T::Item> {
779780
let mut iter = it.into_iter();
@@ -784,24 +785,26 @@ impl AttributesExt for [ast::Attribute] {
784785
Some(item)
785786
}
786787

787-
let mut cfg = if doc_cfg_active {
788+
let mut cfg = if doc_cfg_active || doc_auto_cfg_active {
788789
let mut doc_cfg = self
789790
.iter()
790791
.filter(|attr| attr.has_name(sym::doc))
791792
.flat_map(|attr| attr.meta_item_list().unwrap_or_else(Vec::new))
792793
.filter(|attr| attr.has_name(sym::cfg))
793794
.peekable();
794-
if doc_cfg.peek().is_some() {
795+
if doc_cfg.peek().is_some() && doc_cfg_active {
795796
doc_cfg
796797
.filter_map(|attr| Cfg::parse(attr.meta_item()?).ok())
797798
.fold(Cfg::True, |cfg, new_cfg| cfg & new_cfg)
798-
} else {
799+
} else if doc_auto_cfg_active {
799800
self.iter()
800801
.filter(|attr| attr.has_name(sym::cfg))
801802
.filter_map(|attr| single(attr.meta_item_list()?))
802803
.filter_map(|attr| Cfg::parse(attr.meta_item()?).ok())
803804
.filter(|cfg| !hidden_cfg.contains(cfg))
804805
.fold(Cfg::True, |cfg, new_cfg| cfg & new_cfg)
806+
} else {
807+
Cfg::True
805808
}
806809
} else {
807810
Cfg::True

src/test/rustdoc/doc-auto-cfg.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#![feature(doc_auto_cfg)]
2+
3+
#![crate_name = "foo"]
4+
5+
// @has foo/fn.foo.html
6+
// @has - '//*[@class="item-info"]/*[@class="stab portability"]' 'non-test'
7+
#[cfg(not(test))]
8+
pub fn foo() {}

src/test/rustdoc/doc-cfg-hide.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#![crate_name = "oud"]
2-
#![feature(doc_cfg, doc_cfg_hide)]
2+
#![feature(doc_auto_cfg, doc_cfg, doc_cfg_hide)]
33

44
#![doc(cfg_hide(feature = "solecism"))]
55

src/test/rustdoc/doc-cfg-implicit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#![crate_name = "funambulism"]
2-
#![feature(doc_cfg)]
2+
#![feature(doc_auto_cfg, doc_cfg)]
33

44
// @has 'funambulism/struct.Disorbed.html'
55
// @count - '//*[@class="stab portability"]' 1
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#![feature(doc_cfg)]
2+
3+
#![crate_name = "foo"]
4+
5+
// @has foo/fn.foo.html
6+
// @count - '//*[@class="item-info"]/*[@class="stab portability"]' 0
7+
#[cfg(not(test))]
8+
pub fn foo() {}

0 commit comments

Comments
 (0)