Closed
Description
Very recently, I started seeing the above warning running cargo +nightly udeps
.
To reproduce, create a lib.rs file with the following contents:
#![allow(dead_code)]
#[cfg(test)]
fn foo() {}
Running cargo +nightly udeps
, I see the following warning:
warning: unexpected `cfg` condition name: `test`
--> src/lib.rs:3:7
|
3 | #[cfg(test)]
| ^^^^
|
= help: expected names are: `clippy`, `debug_assertions`, `doc`, `docsrs`, `doctest`, `feature`, `fmt_debug`, `miri`, `overflow_checks`, `panic`, `proc_macro`, `relocation_model`, `rustfmt`, `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`, `ub_checks`, `unix`, and `windows`
= help: consider using a Cargo feature instead
= help: or consider adding in `Cargo.toml` the `check-cfg` lint config for the lint:
[lints.rust]
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(test)'] }
= help: or consider adding `println!("cargo::rustc-check-cfg=cfg(test)");` to the top of the `build.rs`
= note: see <https://doc.rust-lang.org/nightly/rustc/check-cfg/cargo-specifics.html> for more information about checking conditional configuration
= note: `#[warn(unexpected_cfgs)]` on by default
I don't know whether this is helpful, but here are the rustc
commands I see used by cargo +nightly check
and cargo +nightly udeps
(respectively). Note the difference in the --check-cfg
options.
path-to-rustc --crate-name a --edition=2021 src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=149 --crate-type lib --emit=dep-info,metadata -C embed-bitcode=no -C debuginfo=2 -C split-debuginfo=unpacked --check-cfg 'cfg(docsrs,test)' --check-cfg 'cfg(feature, values())' -C metadata=3460fd85e03fd244 -C extra-filename=-f8564086733bb9d3 --out-dir .../a/target/debug/deps -C incremental=.../a/target/debug/incremental -L dependency=.../a/target/debug/deps
path-to-rustc --crate-name a --edition=2021 src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=149 --crate-type lib --emit=dep-info,metadata -C embed-bitcode=no -C debuginfo=2 -C split-debuginfo=unpacked --check-cfg 'cfg(docsrs)' --check-cfg 'cfg(feature, values())' -C metadata=8797eb2d44e088bf -C extra-filename=-8797eb2d44e088bf --out-dir .../a/target/debug/deps -C incremental=.../a/target/debug/incremental -L dependency=.../a/target/debug/deps -Z binary-dep-depinfo
Metadata
Metadata
Assignees
Labels
No labels