New warning on nightly: unexpected_cfgs
Here's an example:
warning: unexpected `cfg` condition name: `ci_arti_stable`
--> crates/tor-protover/src/lib.rs:4:17
|
4 | #![cfg_attr(not(ci_arti_stable), allow(renamed_and_removed_lints))]
| ^^^^^^^^^^^^^^
|
= 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(ci_arti_stable)");` 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: `#[warn(unexpected_cfgs)]` on by default
In general, I'd be in favor of keeping this warning, since it does spot the otherwise easy-to-overlook problem of misspelling a cfg
condition. But it does create a warning on every crate we have, because our default lint blob includes these:
#![cfg_attr(not(ci_arti_stable), allow(renamed_and_removed_lints))]
#![cfg_attr(not(ci_arti_nightly), allow(unknown_lints))]
Possible solutions, many of them bad:
- As suggested in the warning, use a cargo feature instead.
- As suggested in the warning, use a
build.rs
in every crate to explicitly allow this cfg. - Add a blanket
#![allow(unexpected_cfgs)]
. - Use
include!
trickery; by default, include a file that has exactly these blobs, but in our CI replace that empty file with something else. - Use a tweaked
add_warnings
or similar script to adjust the warnings block at CI time.
I think I favor 5.