Skip to content

check-cfg does not appear to honor target-spec json #108941

Closed
@ehuss

Description

@ehuss

--check-cfg=values() doesn't seem to know that custom targets can extend the set of values.

Steps

The following creates a custom spec with a target_os="ericos".

  1. cargo new --lib foo
  2. cd foo
  3. rm src/lib.rs
  4. cat <<EOF > src/lib.rs
    #![no_std]
    
    #[cfg(target_os = "macos")]
    pub fn macos() {}
    
    #[cfg(target_os = "ericos")]
    pub fn eric() {}
    EOF
  5. cat << EOF > custom.json
    {
        "llvm-target": "x86_64-unknown-none-gnu",
        "data-layout": "e-m:e-i64:64-f80:128-n8:16:32:64-S128",
        "arch": "x86_64",
        "target-endian": "little",
        "target-pointer-width": "64",
        "target-c-int-width": "32",
        "os": "ericos",
        "linker-flavor": "ld.lld",
        "linker": "rust-lld",
        "executables": true
    }
  6. cargo check --target custom.json -Zbuild-std=core -Zcheck-cfg=values

Expected

No warning

Actual

Got the warning:

warning: unexpected `cfg` condition value
 --> src/lib.rs:6:7
  |
6 | #[cfg(target_os = "ericos")]
  |       ^^^^^^^^^^^^^^^^^^^^
  |
  = note: expected values for `target_os` are: aix, android, cuda, dragonfly, emscripten, espidf, freebsd, fuchsia, haiku, hermit, horizon, illumos, ios, l4re, linux, macos, netbsd, none, nto, openbsd, psp, redox, solaris, solid_asp3, tvos, uefi, unknown, vita, vxworks, wasi, watchos, windows, xous
  = note: `#[warn(unexpected_cfgs)]` on by default

warning: unexpected condition value `ericos` for condition name `target_os`
  |
  = help: was set with `--cfg` but isn't in the `--check-cfg` expected values

Meta

rustc 1.69.0-nightly (7281249a1 2023-02-27)
binary: rustc
commit-hash: 7281249a19a9755e9d889ee251ec323629caadab
commit-date: 2023-02-27
host: aarch64-apple-darwin
release: 1.69.0-nightly
LLVM version: 15.0.7

cc @Urgau

Metadata

Metadata

Assignees

Labels

A-target-specsArea: Compile-target specificationsC-bugCategory: This is a bug.F-check-cfg--check-cfg

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions