rust-fuzz / cargo-fuzz

Command line helpers for fuzzing
https://rust-fuzz.github.io/book/cargo-fuzz.html
Apache License 2.0
1.48k stars 108 forks source link

error: unexpected `cfg` condition name: `fuzzing` #372

Open larseggert opened 2 months ago

larseggert commented 2 months ago

cargo 1.80.0-nightly (05364cb2f 2024-05-03) now throws the following clippy error:

error: unexpected `cfg` condition name: `fuzzing`
  --> neqo-transport/src/lib.rs:21:7
   |
21 | #[cfg(fuzzing)]
   |       ^^^^^^^
   |
   = help: expected names are: `clippy`, `debug_assertions`, `doc`, `docsrs`, `doctest`, `feature`, `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`, `ub_checks`, `unix`, `windows`
   = help: consider using a Cargo feature instead or adding `println!("cargo::rustc-check-cfg=cfg(fuzzing)");` to the top of the `build.rs`
   = note: see <https://doc.rust-lang.org/nightly/cargo/reference/build-scripts.html#rustc-check-cfg> for more information about checking conditional configuration
   = note: `-D unexpected-cfgs` implied by `-D warnings`
   = help: to override `-D warnings` add `#[allow(unexpected_cfgs)]`
nagisa commented 2 months ago

This is when running clippy or is this reproducible with cargo check as well? Well, unfortunately, I don't think this is something we can fix on our side. Using and suggesting use of cfg(fuzzing) follows a well established example and it would be the tools that use the --check-cfg the way they do that are overzealous here (especially if they fail to provide mechanisms to modify the behaviour easily.)

I would report this issue against cargo (if the issue is reproducible with cargo check.)

kpcyrd commented 2 months ago

I assume this is related to this recent change: https://blog.rust-lang.org/2024/05/06/check-cfg.html

larseggert commented 2 months ago

@kpcyrd Yes, it is. Sorry, I should have said so in the report.

Urgau commented 1 month ago

With the release of rust-lang/cargo#13913 (in nightly-2024-05-19), Cargo has gain the ability to declare --check-cfg args directly in the [lints] table with [lints.rust.unexpected_cfgs.check-cfg][^1]:

Cargo.toml:

[lints.rust]
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(fuzzing)'] }

I recommand directly suggesting it in the README.md, although the lint diagnostic should already suggest that.

[^1]: take effect on Rust 1.80 (current nightly), is ignored on Rust 1.79 (current beta), and produce an unused warning below