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

rustdoc doesn't gate cfg(true/false) within doc(cfg(..)) #138113

Closed
Urgau opened this issue Mar 6, 2025 · 2 comments · Fixed by #138293
Closed

rustdoc doesn't gate cfg(true/false) within doc(cfg(..)) #138113

Urgau opened this issue Mar 6, 2025 · 2 comments · Fixed by #138293
Labels
C-bug Category: This is a bug. F-doc_cfg `#![feature(doc_cfg)]` T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@Urgau
Copy link
Member

Urgau commented Mar 6, 2025

I tried this code:

// #![feature(cfg_boolean_literals)] should be required
#![feature(doc_cfg)]

#[doc(cfg(false))]
pub fn foo() {}

#[doc(cfg(true))]
pub fn bar() {}

I expected to see this happen: An error requiring #![feature(cfg_boolean_literals)], as is the case currently when done #[cfg(true)].

Instead, this happened: The documenation is generated and no extra feature gate is required.

Meta

rustdoc --version --verbose:

rustdoc 1.87.0-nightly (e16a049ad 2025-03-03)
binary: rustdoc
commit-hash: e16a049adbf94d610787430b6efdf31d896dc5b6
commit-date: 2025-03-03
host: x86_64-unknown-linux-gnu
release: 1.87.0-nightly
LLVM version: 20.1.0
@Urgau Urgau added C-bug Category: This is a bug. F-doc_cfg `#![feature(doc_cfg)]` T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels Mar 6, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Mar 6, 2025
@GuillaumeGomez GuillaumeGomez removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Mar 6, 2025
@Urgau
Copy link
Member Author

Urgau commented Mar 6, 2025

The current feature gating is done (for rustc) when evaluating the cfg, maybe rustdoc should do the same, even through it will just discard the result.

gate_cfg(
&(
if *b { kw::True } else { kw::False },
sym::cfg_boolean_literals,
|features: &Features| features.cfg_boolean_literals(),
),
cfg.span(),
sess,
features,
);

@Urgau
Copy link
Member Author

Urgau commented Mar 6, 2025

And if rustdoc where to call cfg_matches (one function upper), then #[doc(cfg(...))] would get check-cfg for free, as it's checked in that function.

jieyouxu added a commit to jieyouxu/rust that referenced this issue Mar 23, 2025
…eGomez

rustdoc: Gate unstable `doc(cfg())` predicates

Fixes rust-lang#138113

Since the extraction process treats `cfg(true)` as having no cfg attribute, we have to do the gating during parsing; so we remove the unused `features` arg from `Cfg::matches`
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Mar 23, 2025
…eGomez

rustdoc: Gate unstable `doc(cfg())` predicates

Fixes rust-lang#138113

Since the extraction process treats `cfg(true)` as having no cfg attribute, we have to do the gating during parsing; so we remove the unused `features` arg from `Cfg::matches`
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Mar 23, 2025
…eGomez

rustdoc: Gate unstable `doc(cfg())` predicates

Fixes rust-lang#138113

Since the extraction process treats `cfg(true)` as having no cfg attribute, we have to do the gating during parsing; so we remove the unused `features` arg from `Cfg::matches`
@bors bors closed this as completed in 856ba39 Mar 24, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Mar 24, 2025
Rollup merge of rust-lang#138293 - clubby789:doc-cfg-gate, r=GuillaumeGomez

rustdoc: Gate unstable `doc(cfg())` predicates

Fixes rust-lang#138113

Since the extraction process treats `cfg(true)` as having no cfg attribute, we have to do the gating during parsing; so we remove the unused `features` arg from `Cfg::matches`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. F-doc_cfg `#![feature(doc_cfg)]` T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants