Skip to content

Make check-cfg diagnostics work in #[doc(cfg(..))] #140894

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

Merged
merged 3 commits into from
May 28, 2025

Conversation

Urgau
Copy link
Member

@Urgau Urgau commented May 10, 2025

This PR makes it so that the check-cfg unexpected_cfgs lint, is correctly emitted in rustdoc's #[doc(cfg(..))].

This is achieved by adding a custom trait to cfg_matches (the method that emits the lint) which permits rustc and rustdoc to each have their way to emitting lints (via buffered lints/AST for rustc and via TyCtxt/HIR for rustdoc).

The reason this is required is because buffered lints operates on the AST but rustdoc uses the HIR and by the time rustdoc calls cfg_matches we are way passed the point where buffered lints have been drain and emitted.

Best reviewed commit by commit.

r? @jieyouxu (for the compiler part)
r? @GuillaumeGomez (for the rustdoc part)

@Urgau Urgau added the F-check-cfg --check-cfg label May 10, 2025
@rustbot rustbot added A-attributes Area: Attributes (`#[…]`, `#![…]`) S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels May 10, 2025
@rustbot
Copy link
Collaborator

rustbot commented May 10, 2025

Some changes occurred in compiler/rustc_attr_parsing

cc @jdonszelmann

Copy link
Member

@jieyouxu jieyouxu left a comment

Choose a reason for hiding this comment

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

Compiler changes seem fine

@jieyouxu
Copy link
Member

jieyouxu commented May 16, 2025

(Unassigning myself to get this out of my review queue, feel free to ping me if this needs a re-review.)

@jieyouxu jieyouxu removed their assignment May 16, 2025
Copy link
Member

@GuillaumeGomez GuillaumeGomez left a comment

Choose a reason for hiding this comment

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

Just one small nit, otherwise looks all good to me. Good work! Once fixed, r=me.

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 26, 2025
@Urgau Urgau force-pushed the check-cfg-rustdoc branch from 4923d4b to 3fd0265 Compare May 26, 2025 19:52
@Urgau Urgau dismissed GuillaumeGomez’s stale review May 26, 2025 21:56

Review comments addressed.

@Urgau
Copy link
Member Author

Urgau commented May 26, 2025

@bors r=GuillaumeGomez

@bors
Copy link
Collaborator

bors commented May 26, 2025

📌 Commit 3fd0265 has been approved by GuillaumeGomez

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels May 26, 2025
bors added a commit that referenced this pull request May 28, 2025
Rollup of 8 pull requests

Successful merges:

 - #140367 (add `asm_cfg`: `#[cfg(...)]` within `asm!`)
 - #140894 (Make check-cfg diagnostics work in `#[doc(cfg(..))]`)
 - #141252 (gvn: bail out unavoidable non-ssa locals in repeat)
 - #141517 (rustdoc: use descriptive tooltip if doctest is conditionally ignored)
 - #141551 (Make two transmute-related MIR lints into HIR lint)
 - #141591 (ci: fix llvm test coverage)
 - #141647 (Bump master `stage0` compiler)
 - #141659 (Add `Result::map_or_default` and `Option::map_or_default`)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 0c2fbe5 into rust-lang:master May 28, 2025
7 checks passed
@rustbot rustbot added this to the 1.89.0 milestone May 28, 2025
rust-timer added a commit that referenced this pull request May 28, 2025
Rollup merge of #140894 - Urgau:check-cfg-rustdoc, r=GuillaumeGomez

Make check-cfg diagnostics work in `#[doc(cfg(..))]`

This PR makes it so that the check-cfg `unexpected_cfgs` lint, is correctly emitted in `rustdoc`'s `#[doc(cfg(..))]`.

This is achieved by adding a custom trait to `cfg_matches` (the method that emits the lint) which permits `rustc` and `rustdoc` to each have their way to emitting lints (via buffered lints/AST for `rustc` and via `TyCtxt`/HIR for `rustdoc`).

The reason this is required is because buffered lints operates on the AST but `rustdoc` uses the HIR and by the time `rustdoc` calls `cfg_matches` we are way passed the point where buffered lints have been drain and emitted.

Best reviewed commit by commit.

r? `@jieyouxu` (for the compiler part)
r? `@GuillaumeGomez` (for the rustdoc part)
github-actions bot pushed a commit to rust-lang/miri that referenced this pull request May 28, 2025
Rollup of 8 pull requests

Successful merges:

 - rust-lang/rust#140367 (add `asm_cfg`: `#[cfg(...)]` within `asm!`)
 - rust-lang/rust#140894 (Make check-cfg diagnostics work in `#[doc(cfg(..))]`)
 - rust-lang/rust#141252 (gvn: bail out unavoidable non-ssa locals in repeat)
 - rust-lang/rust#141517 (rustdoc: use descriptive tooltip if doctest is conditionally ignored)
 - rust-lang/rust#141551 (Make two transmute-related MIR lints into HIR lint)
 - rust-lang/rust#141591 (ci: fix llvm test coverage)
 - rust-lang/rust#141647 (Bump master `stage0` compiler)
 - rust-lang/rust#141659 (Add `Result::map_or_default` and `Option::map_or_default`)

r? `@ghost`
`@rustbot` modify labels: rollup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-attributes Area: Attributes (`#[…]`, `#![…]`) F-check-cfg --check-cfg S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants