Split doc_cfg and doc_auto_cfg features
This commit is contained in:
parent
dca3f1b786
commit
d50a4753b8
7 changed files with 28 additions and 5 deletions
|
@ -688,6 +688,9 @@ declare_features! (
|
||||||
/// not changed from prior instances of the same struct (RFC #2528)
|
/// not changed from prior instances of the same struct (RFC #2528)
|
||||||
(incomplete, type_changing_struct_update, "1.58.0", Some(86555), None),
|
(incomplete, type_changing_struct_update, "1.58.0", Some(86555), None),
|
||||||
|
|
||||||
|
/// Tells rustdoc to automatically generate `#[doc(cfg(...))]`.
|
||||||
|
(active, doc_auto_cfg, "1.58.0", Some(43781), None),
|
||||||
|
|
||||||
// -------------------------------------------------------------------------
|
// -------------------------------------------------------------------------
|
||||||
// feature-group-end: actual feature gates
|
// feature-group-end: actual feature gates
|
||||||
// -------------------------------------------------------------------------
|
// -------------------------------------------------------------------------
|
||||||
|
|
|
@ -549,6 +549,7 @@ symbols! {
|
||||||
div_assign,
|
div_assign,
|
||||||
doc,
|
doc,
|
||||||
doc_alias,
|
doc_alias,
|
||||||
|
doc_auto_cfg,
|
||||||
doc_cfg,
|
doc_cfg,
|
||||||
doc_cfg_hide,
|
doc_cfg_hide,
|
||||||
doc_keyword,
|
doc_keyword,
|
||||||
|
|
|
@ -789,6 +789,7 @@ impl AttributesExt for [ast::Attribute] {
|
||||||
fn cfg(&self, tcx: TyCtxt<'_>, hidden_cfg: &FxHashSet<Cfg>) -> Option<Arc<Cfg>> {
|
fn cfg(&self, tcx: TyCtxt<'_>, hidden_cfg: &FxHashSet<Cfg>) -> Option<Arc<Cfg>> {
|
||||||
let sess = tcx.sess;
|
let sess = tcx.sess;
|
||||||
let doc_cfg_active = tcx.features().doc_cfg;
|
let doc_cfg_active = tcx.features().doc_cfg;
|
||||||
|
let doc_auto_cfg_active = tcx.features().doc_auto_cfg;
|
||||||
|
|
||||||
fn single<T: IntoIterator>(it: T) -> Option<T::Item> {
|
fn single<T: IntoIterator>(it: T) -> Option<T::Item> {
|
||||||
let mut iter = it.into_iter();
|
let mut iter = it.into_iter();
|
||||||
|
@ -799,24 +800,26 @@ impl AttributesExt for [ast::Attribute] {
|
||||||
Some(item)
|
Some(item)
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut cfg = if doc_cfg_active {
|
let mut cfg = if doc_cfg_active || doc_auto_cfg_active {
|
||||||
let mut doc_cfg = self
|
let mut doc_cfg = self
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|attr| attr.has_name(sym::doc))
|
.filter(|attr| attr.has_name(sym::doc))
|
||||||
.flat_map(|attr| attr.meta_item_list().unwrap_or_else(Vec::new))
|
.flat_map(|attr| attr.meta_item_list().unwrap_or_else(Vec::new))
|
||||||
.filter(|attr| attr.has_name(sym::cfg))
|
.filter(|attr| attr.has_name(sym::cfg))
|
||||||
.peekable();
|
.peekable();
|
||||||
if doc_cfg.peek().is_some() {
|
if doc_cfg.peek().is_some() && doc_cfg_active {
|
||||||
doc_cfg
|
doc_cfg
|
||||||
.filter_map(|attr| Cfg::parse(attr.meta_item()?).ok())
|
.filter_map(|attr| Cfg::parse(attr.meta_item()?).ok())
|
||||||
.fold(Cfg::True, |cfg, new_cfg| cfg & new_cfg)
|
.fold(Cfg::True, |cfg, new_cfg| cfg & new_cfg)
|
||||||
} else {
|
} else if doc_auto_cfg_active {
|
||||||
self.iter()
|
self.iter()
|
||||||
.filter(|attr| attr.has_name(sym::cfg))
|
.filter(|attr| attr.has_name(sym::cfg))
|
||||||
.filter_map(|attr| single(attr.meta_item_list()?))
|
.filter_map(|attr| single(attr.meta_item_list()?))
|
||||||
.filter_map(|attr| Cfg::parse(attr.meta_item()?).ok())
|
.filter_map(|attr| Cfg::parse(attr.meta_item()?).ok())
|
||||||
.filter(|cfg| !hidden_cfg.contains(cfg))
|
.filter(|cfg| !hidden_cfg.contains(cfg))
|
||||||
.fold(Cfg::True, |cfg, new_cfg| cfg & new_cfg)
|
.fold(Cfg::True, |cfg, new_cfg| cfg & new_cfg)
|
||||||
|
} else {
|
||||||
|
Cfg::True
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Cfg::True
|
Cfg::True
|
||||||
|
|
8
src/test/rustdoc/doc-auto-cfg.rs
Normal file
8
src/test/rustdoc/doc-auto-cfg.rs
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
#![feature(doc_auto_cfg)]
|
||||||
|
|
||||||
|
#![crate_name = "foo"]
|
||||||
|
|
||||||
|
// @has foo/fn.foo.html
|
||||||
|
// @has - '//*[@class="item-info"]/*[@class="stab portability"]' 'non-test'
|
||||||
|
#[cfg(not(test))]
|
||||||
|
pub fn foo() {}
|
|
@ -1,5 +1,5 @@
|
||||||
#![crate_name = "oud"]
|
#![crate_name = "oud"]
|
||||||
#![feature(doc_cfg, doc_cfg_hide)]
|
#![feature(doc_auto_cfg, doc_cfg, doc_cfg_hide)]
|
||||||
|
|
||||||
#![doc(cfg_hide(feature = "solecism"))]
|
#![doc(cfg_hide(feature = "solecism"))]
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#![crate_name = "funambulism"]
|
#![crate_name = "funambulism"]
|
||||||
#![feature(doc_cfg)]
|
#![feature(doc_auto_cfg, doc_cfg)]
|
||||||
|
|
||||||
// @has 'funambulism/struct.Disorbed.html'
|
// @has 'funambulism/struct.Disorbed.html'
|
||||||
// @count - '//*[@class="stab portability"]' 1
|
// @count - '//*[@class="stab portability"]' 1
|
||||||
|
|
8
src/test/rustdoc/feature-gate-doc_auto_cfg.rs
Normal file
8
src/test/rustdoc/feature-gate-doc_auto_cfg.rs
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
#![feature(doc_cfg)]
|
||||||
|
|
||||||
|
#![crate_name = "foo"]
|
||||||
|
|
||||||
|
// @has foo/fn.foo.html
|
||||||
|
// @count - '//*[@class="item-info"]/*[@class="stab portability"]' 0
|
||||||
|
#[cfg(not(test))]
|
||||||
|
pub fn foo() {}
|
Loading…
Add table
Reference in a new issue