From 220ca0ca9dddba8cc19d19968af7988ca3fc7d7c Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sat, 4 May 2024 19:59:44 -0700 Subject: [PATCH] Resolve unexpected_cfgs warning warning: unexpected `cfg` condition name: `serde_build_from_git` --> serde_derive_internals/lib.rs:45:12 | 45 | #[cfg_attr(serde_build_from_git, path = "../serde_derive/src/internals/mod.rs")] | ^^^^^^^^^^^^^^^^^^^^ | = help: expected names are: `clippy`, `debug_assertions`, `doc`, `docsrs`, `doctest`, `feature`, `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`, `test`, `ub_checks`, `unix`, `windows` = help: consider using a Cargo feature instead or adding `println!("cargo::rustc-check-cfg=cfg(serde_build_from_git)");` to the top of the `build.rs` = note: see for more information about checking conditional configuration = note: `#[warn(unexpected_cfgs)]` on by default warning: unexpected `cfg` condition name: `serde_build_from_git` --> serde_derive_internals/lib.rs:46:16 | 46 | #[cfg_attr(not(serde_build_from_git), path = "src/mod.rs")] | ^^^^^^^^^^^^^^^^^^^^ | = help: consider using a Cargo feature instead or adding `println!("cargo::rustc-check-cfg=cfg(serde_build_from_git)");` to the top of the `build.rs` = note: see for more information about checking conditional configuration warning: unexpected `cfg` condition value: `deserialize_in_place` --> serde_derive_internals/src/attr.rs:276:11 | 276 | #[cfg(feature = "deserialize_in_place")] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove the condition | = note: no expected values for `feature` = help: consider adding `deserialize_in_place` as a feature in `Cargo.toml` = note: see for more information about checking conditional configuration warning: unexpected `cfg` condition name: `exhaustive` --> serde_derive_internals/src/attr.rs:1797:31 | 1797 | #![cfg_attr(all(test, exhaustive), deny(non_exhaustive_omitted_patterns))] | ^^^^^^^^^^ | = help: consider using a Cargo feature instead or adding `println!("cargo::rustc-check-cfg=cfg(exhaustive)");` to the top of the `build.rs` = note: see for more information about checking conditional configuration warning: unexpected `cfg` condition name: `exhaustive` --> serde_derive_internals/src/receiver.rs:110:35 | 110 | #![cfg_attr(all(test, exhaustive), deny(non_exhaustive_omitted_patterns))] | ^^^^^^^^^^ | = help: consider using a Cargo feature instead or adding `println!("cargo::rustc-check-cfg=cfg(exhaustive)");` to the top of the `build.rs` = note: see for more information about checking conditional configuration warning: unexpected `cfg` condition name: `exhaustive` --> serde_derive_internals/src/receiver.rs:181:47 | 181 | #![cfg_attr(all(test, exhaustive), deny(non_exhaustive_omitted_patterns))] | ^^^^^^^^^^ | = help: consider using a Cargo feature instead or adding `println!("cargo::rustc-check-cfg=cfg(exhaustive)");` to the top of the `build.rs` = note: see for more information about checking conditional configuration warning: unexpected `cfg` condition name: `exhaustive` --> serde_derive_internals/src/receiver.rs:210:35 | 210 | #![cfg_attr(all(test, exhaustive), deny(non_exhaustive_omitted_patterns))] | ^^^^^^^^^^ | = help: consider using a Cargo feature instead or adding `println!("cargo::rustc-check-cfg=cfg(exhaustive)");` to the top of the `build.rs` = note: see for more information about checking conditional configuration warning: unexpected `cfg` condition name: `exhaustive` --> serde_derive_internals/src/receiver.rs:231:43 | 231 | #![cfg_attr(all(test, exhaustive), deny(non_exhaustive_omitted_patterns))] | ^^^^^^^^^^ | = help: consider using a Cargo feature instead or adding `println!("cargo::rustc-check-cfg=cfg(exhaustive)");` to the top of the `build.rs` = note: see for more information about checking conditional configuration warning: unexpected `cfg` condition name: `exhaustive` --> serde_derive/src/lib.rs:62:23 | 62 | #![cfg_attr(all(test, exhaustive), feature(non_exhaustive_omitted_patterns_lint))] | ^^^^^^^^^^ | = help: expected names are: `clippy`, `debug_assertions`, `doc`, `docsrs`, `doctest`, `feature`, `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`, `test`, `ub_checks`, `unix`, `windows` = help: consider using a Cargo feature instead or adding `println!("cargo::rustc-check-cfg=cfg(exhaustive)");` to the top of the `build.rs` = note: see for more information about checking conditional configuration = note: `#[warn(unexpected_cfgs)]` on by default warning: unexpected `cfg` condition name: `exhaustive` --> serde_derive/src/internals/attr.rs:1797:31 | 1797 | #![cfg_attr(all(test, exhaustive), deny(non_exhaustive_omitted_patterns))] | ^^^^^^^^^^ | = help: consider using a Cargo feature instead or adding `println!("cargo::rustc-check-cfg=cfg(exhaustive)");` to the top of the `build.rs` = note: see for more information about checking conditional configuration warning: unexpected `cfg` condition name: `exhaustive` --> serde_derive/src/internals/receiver.rs:110:35 | 110 | #![cfg_attr(all(test, exhaustive), deny(non_exhaustive_omitted_patterns))] | ^^^^^^^^^^ | = help: consider using a Cargo feature instead or adding `println!("cargo::rustc-check-cfg=cfg(exhaustive)");` to the top of the `build.rs` = note: see for more information about checking conditional configuration warning: unexpected `cfg` condition name: `exhaustive` --> serde_derive/src/internals/receiver.rs:181:47 | 181 | #![cfg_attr(all(test, exhaustive), deny(non_exhaustive_omitted_patterns))] | ^^^^^^^^^^ | = help: consider using a Cargo feature instead or adding `println!("cargo::rustc-check-cfg=cfg(exhaustive)");` to the top of the `build.rs` = note: see for more information about checking conditional configuration warning: unexpected `cfg` condition name: `exhaustive` --> serde_derive/src/internals/receiver.rs:210:35 | 210 | #![cfg_attr(all(test, exhaustive), deny(non_exhaustive_omitted_patterns))] | ^^^^^^^^^^ | = help: consider using a Cargo feature instead or adding `println!("cargo::rustc-check-cfg=cfg(exhaustive)");` to the top of the `build.rs` = note: see for more information about checking conditional configuration warning: unexpected `cfg` condition name: `exhaustive` --> serde_derive/src/internals/receiver.rs:231:43 | 231 | #![cfg_attr(all(test, exhaustive), deny(non_exhaustive_omitted_patterns))] | ^^^^^^^^^^ | = help: consider using a Cargo feature instead or adding `println!("cargo::rustc-check-cfg=cfg(exhaustive)");` to the top of the `build.rs` = note: see for more information about checking conditional configuration warning: unexpected `cfg` condition name: `exhaustive` --> serde_derive/src/bound.rs:147:39 | 147 | #![cfg_attr(all(test, exhaustive), deny(non_exhaustive_omitted_patterns))] | ^^^^^^^^^^ | = help: consider using a Cargo feature instead or adding `println!("cargo::rustc-check-cfg=cfg(exhaustive)");` to the top of the `build.rs` = note: see for more information about checking conditional configuration warning: unexpected `cfg` condition name: `exhaustive` --> serde_derive/src/bound.rs:199:51 | 199 | ... #![cfg_attr(all(test, exhaustive), deny(non_exhaustive_omitted_patterns))] | ^^^^^^^^^^ | = help: consider using a Cargo feature instead or adding `println!("cargo::rustc-check-cfg=cfg(exhaustive)");` to the top of the `build.rs` = note: see for more information about checking conditional configuration warning: unexpected `cfg` condition name: `exhaustive` --> serde_derive/src/bound.rs:228:39 | 228 | #![cfg_attr(all(test, exhaustive), deny(non_exhaustive_omitted_patterns))] | ^^^^^^^^^^ | = help: consider using a Cargo feature instead or adding `println!("cargo::rustc-check-cfg=cfg(exhaustive)");` to the top of the `build.rs` = note: see for more information about checking conditional configuration warning: unexpected `cfg` condition name: `systemtime_checked_add` --> test_suite/tests/test_de_error.rs:1527:7 | 1527 | #[cfg(systemtime_checked_add)] | ^^^^^^^^^^^^^^^^^^^^^^ | = help: expected names are: `clippy`, `debug_assertions`, `doc`, `docsrs`, `doctest`, `feature`, `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`, `test`, `ub_checks`, `unix`, `windows` = help: consider using a Cargo feature instead or adding `println!("cargo::rustc-check-cfg=cfg(systemtime_checked_add)");` to the top of the `build.rs` = note: see for more information about checking conditional configuration = note: `#[warn(unexpected_cfgs)]` on by default --- serde/build.rs | 15 +++++++++++++++ serde_derive/Cargo.toml | 1 + serde_derive/build.rs | 7 +++++++ serde_derive/src/lib.rs | 1 + serde_derive_internals/build.rs | 8 ++++++++ serde_derive_internals/lib.rs | 1 + test_suite/tests/test_de_error.rs | 1 - 7 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 serde_derive/build.rs diff --git a/serde/build.rs b/serde/build.rs index 0074df63f..097e5f98f 100644 --- a/serde/build.rs +++ b/serde/build.rs @@ -13,6 +13,21 @@ fn main() { None => return, }; + if minor >= 77 { + println!("cargo:rustc-check-cfg=cfg(doc_cfg)"); + println!("cargo:rustc-check-cfg=cfg(no_core_cstr)"); + println!("cargo:rustc-check-cfg=cfg(no_core_num_saturating)"); + println!("cargo:rustc-check-cfg=cfg(no_core_try_from)"); + println!("cargo:rustc-check-cfg=cfg(no_float_copysign)"); + println!("cargo:rustc-check-cfg=cfg(no_num_nonzero_signed)"); + println!("cargo:rustc-check-cfg=cfg(no_relaxed_trait_bounds)"); + println!("cargo:rustc-check-cfg=cfg(no_serde_derive)"); + println!("cargo:rustc-check-cfg=cfg(no_std_atomic)"); + println!("cargo:rustc-check-cfg=cfg(no_std_atomic64)"); + println!("cargo:rustc-check-cfg=cfg(no_systemtime_checked_add)"); + println!("cargo:rustc-check-cfg=cfg(no_target_has_atomic)"); + } + let target = env::var("TARGET").unwrap(); let emscripten = target == "asmjs-unknown-emscripten" || target == "wasm32-unknown-emscripten"; diff --git a/serde_derive/Cargo.toml b/serde_derive/Cargo.toml index f42fbe547..7b85edb8d 100644 --- a/serde_derive/Cargo.toml +++ b/serde_derive/Cargo.toml @@ -6,6 +6,7 @@ categories = ["no-std", "no-std::no-alloc"] description = "Macros 1.1 implementation of #[derive(Serialize, Deserialize)]" documentation = "https://serde.rs/derive.html" edition = "2015" +exclude = ["build.rs"] homepage = "https://serde.rs" keywords = ["serde", "serialization", "no_std", "derive"] license = "MIT OR Apache-2.0" diff --git a/serde_derive/build.rs b/serde_derive/build.rs new file mode 100644 index 000000000..ecd2acf40 --- /dev/null +++ b/serde_derive/build.rs @@ -0,0 +1,7 @@ +fn main() { + // Warning: build.rs is not published to crates.io. + + println!("cargo:rustc-cfg=check_cfg"); + println!("cargo:rustc-check-cfg=cfg(check_cfg)"); + println!("cargo:rustc-check-cfg=cfg(exhaustive)"); +} diff --git a/serde_derive/src/lib.rs b/serde_derive/src/lib.rs index 393f8074b..cdc3c2b90 100644 --- a/serde_derive/src/lib.rs +++ b/serde_derive/src/lib.rs @@ -14,6 +14,7 @@ //! [https://serde.rs/derive.html]: https://serde.rs/derive.html #![doc(html_root_url = "https://docs.rs/serde_derive/1.0.200")] +#![cfg_attr(not(check_cfg), allow(unexpected_cfgs))] // Ignored clippy lints #![allow( // clippy false positive: https://github.com/rust-lang/rust-clippy/issues/7054 diff --git a/serde_derive_internals/build.rs b/serde_derive_internals/build.rs index 25b5ef313..b2bbb3a56 100644 --- a/serde_derive_internals/build.rs +++ b/serde_derive_internals/build.rs @@ -1,9 +1,17 @@ use std::path::Path; fn main() { + // Warning: build.rs is not published to crates.io. + println!("cargo:rerun-if-changed=build.rs"); println!("cargo:rerun-if-changed=src/mod.rs"); + println!("cargo:rustc-cfg=check_cfg"); + println!("cargo:rustc-check-cfg=cfg(check_cfg)"); + println!("cargo:rustc-check-cfg=cfg(exhaustive)"); + println!("cargo:rustc-check-cfg=cfg(serde_build_from_git)"); + println!("cargo:rustc-check-cfg=cfg(feature, values(\"deserialize_in_place\"))"); + // Sometimes on Windows the git checkout does not correctly wire up the // symlink from serde_derive_internals/src to serde_derive/src/internals. // When this happens we'll just build based on relative paths within the git diff --git a/serde_derive_internals/lib.rs b/serde_derive_internals/lib.rs index 1053b009a..b3d55baac 100644 --- a/serde_derive_internals/lib.rs +++ b/serde_derive_internals/lib.rs @@ -1,4 +1,5 @@ #![doc(html_root_url = "https://docs.rs/serde_derive_internals/0.29.0")] +#![cfg_attr(not(check_cfg), allow(unexpected_cfgs))] // Ignored clippy lints #![allow( clippy::cognitive_complexity, diff --git a/test_suite/tests/test_de_error.rs b/test_suite/tests/test_de_error.rs index 06508cbc8..cae5eddab 100644 --- a/test_suite/tests/test_de_error.rs +++ b/test_suite/tests/test_de_error.rs @@ -1524,7 +1524,6 @@ fn test_systemtime_overflow_struct() { ); } -#[cfg(not(no_systemtime_checked_add))] #[test] fn test_systemtime_overflow() { assert_de_tokens_error::(