Skip to content

Conversation

@JonathanBrouwer
Copy link
Contributor

@JonathanBrouwer JonathanBrouwer commented Nov 22, 2025

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.

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

@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

This comment has been minimized.

@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`
bors added a commit that referenced this pull request Dec 2, 2025
…elmann

Move even more early buffered lints to dyn lint diagnostics

Follow-up to #145881 and #145747.

I originally wanted to migrate most if not the entire rest of the early buffered lints. However, when trying to migrate the buffered lints used by check-cfg I encountered a roadblock. Namely, it depends on `TyCtxt` (well, `Option<TyCtxt>`) which makes it quite hard to migrate (see also #147634 (comment), #147634 (comment) & #149215).

So for now, I won't migrate it (maybe #149215 will find a solution), nor will I migrate the rest since it's quite tedious to migrate these. I'll leave them for future me.
@bors
Copy link
Collaborator

bors commented Dec 5, 2025

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

@JonathanBrouwer JonathanBrouwer added the S-blocked Status: Blocked on something else such as an RFC or other implementation work. label Dec 5, 2025
@JonathanBrouwer
Copy link
Contributor Author

JonathanBrouwer commented Dec 5, 2025

Rebased on #149662

After that PR, this change becomes trivial, we don't need to move the lints and we have access to TyCtxt

@JonathanBrouwer JonathanBrouwer changed the title Move check-cfg lints to rustc_attr_parsing Emit check-cfg during attribute parsing rather than evaluation Dec 5, 2025
@JonathanBrouwer JonathanBrouwer changed the title Emit check-cfg during attribute parsing rather than evaluation Emit check-cfg lints during attribute parsing rather than evaluation Dec 5, 2025
@jdonszelmann jdonszelmann self-assigned this Dec 5, 2025
@JonathanBrouwer JonathanBrouwer marked this pull request as ready for review December 6, 2025 09:39
@rustbot
Copy link
Collaborator

rustbot commented Dec 6, 2025

Some changes occurred in compiler/rustc_attr_parsing

cc @jdonszelmann

Some changes occurred in compiler/rustc_hir/src/attrs

cc @jdonszelmann

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Dec 6, 2025
@JonathanBrouwer
Copy link
Contributor Author

JonathanBrouwer commented Dec 6, 2025

The PR is ready now :)

@JonathanBrouwer JonathanBrouwer removed the S-blocked Status: Blocked on something else such as an RFC or other implementation work. label Dec 6, 2025
| ^ help: found config with similar value: `target_feature = "a"`
|
= help: expected names are: `FALSE` and `test` and 31 more
= help: to expect this configuration use `--check-cfg=cfg(a)`
Copy link
Contributor

Choose a reason for hiding this comment

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

same here etc

Copy link
Contributor

@jdonszelmann jdonszelmann left a comment

Choose a reason for hiding this comment

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

some small comments. Let me know, if I'm wrong about them I'll approve after :)

View changes since this review

pos: usize,
) -> EvalConfigResult {
let res = self.cfg().cfg_true(&attr, node.node_id(), ShouldEmit::ErrorsAndLints);
let res = self.cfg().cfg_true(&attr, ShouldEmit::ErrorsAndLints);
Copy link
Contributor

Choose a reason for hiding this comment

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

do we still need the ShouldEmit. You removed the nodeid and that's usually relevant for emitting lints. So maybe we don't need the should_emit anymore either?

Copy link
Contributor

Choose a reason for hiding this comment

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

I guess you're getting the nodeid out of self now. Maybe should emit as well? Or does that change based on where we call this

Copy link
Contributor Author

@JonathanBrouwer JonathanBrouwer Dec 8, 2025

Choose a reason for hiding this comment

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

The ShouldEmit depends on where we call this indeed. Some cfg attributes are evaluated multiple times and we want to be careful to only emit errors once, that's why the ShouldEmit is an argument here

The node.node_id() was actually incorrect, because that turned out to be always the dummy node id

Copy link
Contributor

Choose a reason for hiding this comment

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

I see, cool!

@jdonszelmann
Copy link
Contributor

@rustbot author

@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 Dec 8, 2025
@rustbot
Copy link
Collaborator

rustbot commented Dec 8, 2025

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@JonathanBrouwer
Copy link
Contributor Author

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Dec 8, 2025
@jdonszelmann
Copy link
Contributor

Looks good then I think. @bors r+ rollup

@bors
Copy link
Collaborator

bors commented Dec 8, 2025

📌 Commit 01576a6 has been approved by jdonszelmann

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-review Status: Awaiting review from the assignee but also interested parties. labels Dec 8, 2025
Zalathar added a commit to Zalathar/rust that referenced this pull request Dec 9, 2025
…szelmann

Emit `check-cfg` lints during attribute parsing rather than evaluation

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.

cc `@jdonszelmann` `@Urgau` for a vibe check if you feel like it
bors added a commit that referenced this pull request Dec 9, 2025
Rollup of 12 pull requests

Successful merges:

 - #147572 (std: Use more `unix.rs` code on WASI targets)
 - #148491 ( Correctly provide suggestions when encountering `async fn` with a `dyn Trait` return type)
 - #149215 (Emit `check-cfg` lints during attribute parsing rather than evaluation)
 - #149652 (Add release notes for 1.92.0)
 - #149720 (rustdoc book: mention inner doc attribute)
 - #149730 (lint: emit proper diagnostic for unsafe binders in improper_ctypes instead of ICE)
 - #149754 (Retire `opt_str2` from compiletest cli parsing)
 - #149755 (bootstrap: Use a `CompiletestMode` enum instead of bare strings)
 - #149763 (Add inline attribute to generated delegation function if needed)
 - #149772 (test: Add a test for 146133)
 - #149779 (Fix typo "an" → "and")
 - #149782 (Remove `[no-mentions]` handler in the triagebot config)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit that referenced this pull request Dec 9, 2025
Rollup of 11 pull requests

Successful merges:

 - #147585 (Suppress the error for private fields with non_exhaustive attribute)
 - #149215 (Emit `check-cfg` lints during attribute parsing rather than evaluation)
 - #149652 (Add release notes for 1.92.0)
 - #149720 (rustdoc book: mention inner doc attribute)
 - #149730 (lint: emit proper diagnostic for unsafe binders in improper_ctypes instead of ICE)
 - #149754 (Retire `opt_str2` from compiletest cli parsing)
 - #149755 (bootstrap: Use a `CompiletestMode` enum instead of bare strings)
 - #149763 (Add inline attribute to generated delegation function if needed)
 - #149772 (test: Add a test for 146133)
 - #149779 (Fix typo "an" → "and")
 - #149782 (Remove `[no-mentions]` handler in the triagebot config)

Failed merges:

 - #148491 ( Correctly provide suggestions when encountering `async fn` with a `dyn Trait` return type)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit ece9977 into rust-lang:main Dec 9, 2025
11 checks passed
@rustbot rustbot added this to the 1.94.0 milestone Dec 9, 2025
rust-timer added a commit that referenced this pull request Dec 9, 2025
Rollup merge of #149215 - JonathanBrouwer:cfg_lints2, r=jdonszelmann

Emit `check-cfg` lints during attribute parsing rather than evaluation

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.

cc ``@jdonszelmann`` ``@Urgau`` for a vibe check if you feel like it
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-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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants