Skip to content

Conversation

@JonathanBrouwer
Copy link
Contributor

The goal of this PR is to make the eval_config_entry not have any side effects, by moving the check-cfg lints to the attribute parsing. This also helps ensure we do emit the lint in situations where the attribute happens to be parsed, but never evaluated. This happens to some cases of the #[link] attribute and some cases of the cfg_select! macro.

Still a draft, so no need to review yet, because:

  • I want to add regression tests
  • I sadly had to remove the TyCtxt from the cargo_macro_help hint, I want to see if there is a way to undo this because the hint was quite nice. For this to work we need to emit early lints for attribute parsing later, because the current place they're emitted does not have access to the TyCtxt. I think this should be doable.
  • Made a draft PR to run some bots on this

cc @jdonszelmann @Urgau for a vibe check if you feel like it

Fixes #149090

@rustbot rustbot added A-attributes Area: Attributes (`#[…]`, `#![…]`) A-meta Area: Issues & PRs about the rust-lang/rust repository itself S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Nov 22, 2025
@rust-log-analyzer

This comment has been minimized.

@Urgau
Copy link
Member

Urgau commented Nov 22, 2025

Does it mean we would get warnings for non-active cfg attributes?

#[cfg(target_os = "lol")] // warn and not active 
#[cfg(unknown)] // currently doesn't warn, since above is not active, but will it with this PR?
fn foo() {}

Regarding the non-accessible TyCtxt, would it be possible to continue to buffer the lint in ParseSess::buffered_lints, using sess.parse_sess.buffer_lint? Or is the problem that you don't emit the lint as a builtin lint and as such no longer have access to TyCtxt?

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer
Copy link
Collaborator

The job pr-check-2 failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
[RUSTC-TIMING] askama test:false 0.171
error[E0061]: this function takes 3 arguments but 4 arguments were supplied
  --> src/librustdoc/passes/check_doc_cfg.rs:34:13
   |
34 |             rustc_lint::decorate_builtin_lint(sess, Some(self.0), builtin_diag, diag)
   |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^       ------------ unexpected argument #2 of type `std::option::Option<TyCtxt<'a>>`
   |
note: function defined here
  --> /checkout/compiler/rustc_lint/src/early/diagnostics.rs:15:8
   |
15 | pub fn decorate_builtin_lint(sess: &Session, diagnostic: BuiltinLintDiag, diag: &mut Diag<'_, ()>) {
   |        ^^^^^^^^^^^^^^^^^^^^^
help: remove the extra argument
   |
34 -             rustc_lint::decorate_builtin_lint(sess, Some(self.0), builtin_diag, diag)
34 +             rustc_lint::decorate_builtin_lint(sess, builtin_diag, diag)
   |

For more information about this error, try `rustc --explain E0061`.
[RUSTC-TIMING] rustdoc test:false 3.572
error: could not compile `rustdoc` (lib) due to 1 previous error

@JonathanBrouwer
Copy link
Contributor Author

JonathanBrouwer commented Nov 25, 2025

Attributes that are configured out (like in your example) are currently not parsed, and therefore this would not cause this warning, preserving the old behavior. I didn't think of this edgecase so I'll make sure to add a test for this.

Indeed currently attribute lints are special and not emitted as a builtin lint. I'm gonna play around with this a bit and see if anything is stopping me from changing that

Zalathar added a commit to Zalathar/rust that referenced this pull request Nov 28, 2025
…r=Urgau

Run `eval_config_entry` on all branches so we always emit lints

Fixes rust-lang#149090

Ideally I'd have liked to fix this issue using rust-lang#149215, and this is still the long term plan, but this is slightly more annoying to implement than I'd have liked to, and this is also a nice and easy solution to the problem.

r? `@tgross35`
rust-timer added a commit that referenced this pull request Nov 28, 2025
Rollup merge of #149380 - JonathanBrouwer:cfg_select_lints, r=Urgau

Run `eval_config_entry` on all branches so we always emit lints

Fixes #149090

Ideally I'd have liked to fix this issue using #149215, and this is still the long term plan, but this is slightly more annoying to implement than I'd have liked to, and this is also a nice and easy solution to the problem.

r? `@tgross35`
RalfJung pushed a commit to RalfJung/miri that referenced this pull request Nov 28, 2025
Run `eval_config_entry` on all branches so we always emit lints

Fixes rust-lang/rust#149090

Ideally I'd have liked to fix this issue using rust-lang/rust#149215, and this is still the long term plan, but this is slightly more annoying to implement than I'd have liked to, and this is also a nice and easy solution to the problem.

r? `@tgross35`
@bors
Copy link
Collaborator

bors commented Nov 28, 2025

☔ The latest upstream changes (presumably #149410) made this pull request unmergeable. Please resolve the merge conflicts.

github-actions bot pushed a commit to rust-lang/rust-analyzer that referenced this pull request Dec 1, 2025
Run `eval_config_entry` on all branches so we always emit lints

Fixes rust-lang/rust#149090

Ideally I'd have liked to fix this issue using rust-lang/rust#149215, and this is still the long term plan, but this is slightly more annoying to implement than I'd have liked to, and this is also a nice and easy solution to the problem.

r? `@tgross35`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-attributes Area: Attributes (`#[…]`, `#![…]`) A-meta Area: Issues & PRs about the rust-lang/rust repository itself S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cfg_select should check for unexpected_cfgs on other arms

5 participants