Skip to content

Suggest name value cfg when only value is used for check-cfg #120427

Closed

Description

Code

#[cfg(linux)]
fn x() {}

fn main() {}

Current output

warning: unexpected `cfg` condition name: `linux`
 --> t.rs:1:7
  |
1 | #[cfg(linux)]
  |       ^^^^^
  |
  = help: expected names are: `debug_assertions`, `doc`, `doctest`, `miri`, `overflow_checks`, `panic`, `proc_macro`, `relocation_model`, `sanitize`, `sanitizer_cfi_generalize_pointers`, `sanitizer_cfi_normalize_integers`, `target_abi`, `target_arch`, `target_endian`, `target_env`, `target_family`, `target_feature`, `target_has_atomic`, `target_has_atomic_equal_alignment`, `target_has_atomic_load_store`, `target_os`, `target_pointer_width`, `target_thread_local`, `target_vendor`, `test`, `unix`, `windows`
  = help: to expect this configuration use `--check-cfg=cfg(linux)`
  = note: see <https://doc.rust-lang.org/nightly/unstable-book/compiler-flags/check-cfg.html> for more information about checking conditional configuration
  = note: `#[warn(unexpected_cfgs)]` on by default

Desired output

= help: try `cfg(target_os = "linux")`

Rationale and extra context

The user wanted something with "linux", and there is a name-value cfg that has the value "linux", so they probably wanted that.

Other cases

many other possible name-value cfgs...

Rust Version

rustc 1.77.0-nightly (5bd5d214e 2024-01-25)

Anything else?

No response

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

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsD-terseDiagnostics: An error or lint that doesn't give enough information about the problem at hand.F-check-cfg--check-cfgT-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

No branches or pull requests

Issue actions