Skip to content

Unexpected cfg condition name diagnostic is sometimes confusing #141440

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

Closed
jieyouxu opened this issue May 23, 2025 · 0 comments · Fixed by #141456
Closed

Unexpected cfg condition name diagnostic is sometimes confusing #141440

jieyouxu opened this issue May 23, 2025 · 0 comments · Fixed by #141456
Labels
A-cfg Area: `cfg` conditional compilation A-diagnostics Area: Messages for errors, warnings, and lints D-confusing Diagnostics: Confusing error or lint that should be reworked. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@jieyouxu
Copy link
Member

Discussion (not in scope for this PR): Maybe this diagnostic is a bit misleading? version is a condition name, but just that the parenthesized name-value form (forgot what that form is called technically) is what's considered valid cfg, and not the version = ".." name-with-literal-value form.

Originally posted by @jieyouxu in #141413 (comment)


If a cfg by the name-with-parenthesized-value form exists (e.g. cfg(version(..))) and the user writes the meta literal(?) form e.g. cfg(version = ".."), we currently produce a diagnostic that says

warning: unexpected `cfg` condition name: `version`

This is technically true, because we don't expect the version = ".." form, we expect the version(..) form.

I wonder if we could clarify the diagnostic here if the version(..) form is a thing but not the version = ".." form.

(Picked version as an example, this is generally applicable.)

@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label May 23, 2025
@jieyouxu jieyouxu added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-cfg Area: `cfg` conditional compilation D-confusing Diagnostics: Confusing error or lint that should be reworked. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels May 23, 2025
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue May 24, 2025
…eyouxu

Suggest correct `version("..")` predicate syntax in check-cfg

This PR specialize the `unexpected_cfgs` lint diagnostic to suggest correct `version("..")` predicate syntax when providing the key-value one, eg. `version = "1.27"`.

Fixes rust-lang#141440
r? `@jieyouxu`
@bors bors closed this as completed in 8019d08 May 24, 2025
rust-timer added a commit that referenced this issue May 24, 2025
Rollup merge of #141456 - Urgau:check-cfg-version-pred, r=jieyouxu

Suggest correct `version("..")` predicate syntax in check-cfg

This PR specialize the `unexpected_cfgs` lint diagnostic to suggest correct `version("..")` predicate syntax when providing the key-value one, eg. `version = "1.27"`.

Fixes #141440
r? ``@jieyouxu``
github-actions bot pushed a commit to rust-lang/miri that referenced this issue May 25, 2025
Suggest correct `version("..")` predicate syntax in check-cfg

This PR specialize the `unexpected_cfgs` lint diagnostic to suggest correct `version("..")` predicate syntax when providing the key-value one, eg. `version = "1.27"`.

Fixes rust-lang/rust#141440
r? ``@jieyouxu``
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-cfg Area: `cfg` conditional compilation A-diagnostics Area: Messages for errors, warnings, and lints D-confusing Diagnostics: Confusing error or lint that should be reworked. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants