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

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

4 participants