Skip to content

Unexpected cfg condition name diagnostic is sometimes confusing #141440

Closed
@jieyouxu

Description

@jieyouxu
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.)

Activity

added
needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.
on May 23, 2025
added
A-diagnosticsArea: Messages for errors, warnings, and lints
T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
A-cfgArea: `cfg` conditional compilation
D-confusingDiagnostics: Confusing error or lint that should be reworked.
and removed
needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.
on May 23, 2025
added 2 commits that reference this issue on May 24, 2025

Rollup merge of rust-lang#141456 - Urgau:check-cfg-version-pred, r=ji…

8bd0ebd

Rollup merge of rust-lang#141456 - Urgau:check-cfg-version-pred, r=ji…

8019d08
added a commit that references this issue on May 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-cfgArea: `cfg` conditional compilationA-diagnosticsArea: Messages for errors, warnings, and lintsD-confusingDiagnostics: Confusing error or lint that should be reworked.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @jieyouxu@rustbot

      Issue actions

        Unexpected cfg condition name diagnostic is sometimes confusing · Issue #141440 · rust-lang/rust