Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split doc_cfg and doc_auto_cfg features #90502

Merged
merged 2 commits into from
Nov 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions compiler/rustc_feature/src/active.rs
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,9 @@ declare_features! (
/// not changed from prior instances of the same struct (RFC #2528)
(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),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this was beta-accepted, I took the liberty of adjusting it to "1.57.0" in #90938. Would someone care to fix that on master as well?


// -------------------------------------------------------------------------
// feature-group-end: actual feature gates
// -------------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_span/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,7 @@ symbols! {
div_assign,
doc,
doc_alias,
doc_auto_cfg,
doc_cfg,
doc_cfg_hide,
doc_keyword,
Expand Down
9 changes: 6 additions & 3 deletions src/librustdoc/clean/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -789,6 +789,7 @@ impl AttributesExt for [ast::Attribute] {
fn cfg(&self, tcx: TyCtxt<'_>, hidden_cfg: &FxHashSet<Cfg>) -> Option<Arc<Cfg>> {
let sess = tcx.sess;
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> {
let mut iter = it.into_iter();
Expand All @@ -799,24 +800,26 @@ impl AttributesExt for [ast::Attribute] {
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
GuillaumeGomez marked this conversation as resolved.
Show resolved Hide resolved
.iter()
.filter(|attr| attr.has_name(sym::doc))
.flat_map(|attr| attr.meta_item_list().unwrap_or_else(Vec::new))
.filter(|attr| attr.has_name(sym::cfg))
.peekable();
if doc_cfg.peek().is_some() {
if doc_cfg.peek().is_some() && doc_cfg_active {
doc_cfg
.filter_map(|attr| Cfg::parse(attr.meta_item()?).ok())
.fold(Cfg::True, |cfg, new_cfg| cfg & new_cfg)
} else {
} else if doc_auto_cfg_active {
GuillaumeGomez marked this conversation as resolved.
Show resolved Hide resolved
self.iter()
.filter(|attr| attr.has_name(sym::cfg))
.filter_map(|attr| single(attr.meta_item_list()?))
.filter_map(|attr| Cfg::parse(attr.meta_item()?).ok())
.filter(|cfg| !hidden_cfg.contains(cfg))
.fold(Cfg::True, |cfg, new_cfg| cfg & new_cfg)
} else {
Cfg::True
}
} else {
Cfg::True
Expand Down
8 changes: 8 additions & 0 deletions src/test/rustdoc/doc-auto-cfg.rs
Original file line number Diff line number Diff line change
@@ -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() {}
2 changes: 1 addition & 1 deletion src/test/rustdoc/doc-cfg-hide.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#![crate_name = "oud"]
#![feature(doc_cfg, doc_cfg_hide)]
#![feature(doc_auto_cfg, doc_cfg, doc_cfg_hide)]

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

Expand Down
2 changes: 1 addition & 1 deletion src/test/rustdoc/doc-cfg-implicit.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#![crate_name = "funambulism"]
#![feature(doc_cfg)]
#![feature(doc_auto_cfg, doc_cfg)]

// @has 'funambulism/struct.Disorbed.html'
// @count - '//*[@class="stab portability"]' 1
Expand Down
8 changes: 8 additions & 0 deletions src/test/rustdoc/feature-gate-doc_auto_cfg.rs
Original file line number Diff line number Diff line change
@@ -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() {}
1 change: 1 addition & 0 deletions src/tools/tidy/src/features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ pub fn check(
&src_path.join("test/ui"),
&src_path.join("test/ui-fulldeps"),
&src_path.join("test/rustdoc-ui"),
&src_path.join("test/rustdoc"),
],
&mut |path| super::filter_dirs(path),
&mut |entry, contents| {
Expand Down