Skip to content
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

warning: unexpected cfg condition name: test #293

Closed
smoelius opened this issue Jan 6, 2025 · 4 comments
Closed

warning: unexpected cfg condition name: test #293

smoelius opened this issue Jan 6, 2025 · 4 comments

Comments

@smoelius
Copy link

smoelius commented Jan 6, 2025

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
smoelius added a commit to trailofbits/dylint that referenced this issue Jan 6, 2025
@smoelius
Copy link
Author

smoelius commented Jan 6, 2025

This PR's merger appears to be the problem: rust-lang/rust#131729

smoelius added a commit to trailofbits/cargo-unmaintained that referenced this issue Jan 6, 2025
smoelius added a commit to trailofbits/dylint that referenced this issue Jan 6, 2025
github-merge-queue bot pushed a commit to trailofbits/dylint that referenced this issue Jan 6, 2025
smoelius added a commit to trailofbits/cargo-unmaintained that referenced this issue Jan 6, 2025
smoelius added a commit to trailofbits/necessist that referenced this issue Jan 6, 2025
github-merge-queue bot pushed a commit to trailofbits/cargo-unmaintained that referenced this issue Jan 6, 2025
@est31
Copy link
Owner

est31 commented Jan 6, 2025

As a workaround, I suppose one can pin the nightly to from before that PR merged (say +nightly-2025-01-01). The corresponding cargo PR seems to be rust-lang/cargo#14963 , but it will be 6 weeks until that arrives on stable.

Until then, I suppose we can just add the flag ourselves, there is infrastructure for that. Alternatively one can request from upstream to have the rustc changes reverted until it arrives in cargo stable.

@est31
Copy link
Owner

est31 commented Jan 9, 2025

Fixed by 4a3d71a . Thanks for the report. I'll do a release in the coming day(s).

@est31 est31 closed this as completed Jan 9, 2025
@smoelius
Copy link
Author

Fixed by 4a3d71a . Thanks for the report. I'll do a release in the coming day(s).

Thanks, @est31!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants