From 2a056890b63f22428ef1b267a206a8b3d43494ab Mon Sep 17 00:00:00 2001 From: Joshua Liebow-Feeser Date: Mon, 6 May 2024 10:50:45 -0700 Subject: [PATCH] [build.rs] Support unexpected_cfgs lint Closes #1201 --- build.rs | 14 ++++++++++++++ src/lib.rs | 6 ++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/build.rs b/build.rs index 39d0002c56..a51361a312 100644 --- a/build.rs +++ b/build.rs @@ -65,6 +65,20 @@ fn main() { let version_cfgs = parse_version_cfgs_from_cargo_toml(); let rustc_version = rustc_version(); + if rustc_version >= (Version { major: 1, minor: 77, patch: 0 }) { + // This tells the `unexpected_cfgs` lint to expect to see all of these + // `cfg`s. The `cargo::` syntax was only added in 1.77, so we don't emit + // these on earlier toolchain versions. + for version_cfg in &version_cfgs { + println!("cargo:rustc-check-cfg=cfg({})", version_cfg.cfg_name); + } + // TODO(https://github.com/rust-lang/rust/issues/124816): Remove these + // once they're no longer needed. + println!("cargo:rustc-check-cfg=cfg(doc_cfg)"); + println!("cargo:rustc-check-cfg=cfg(kani)"); + println!("cargo:rustc-check-cfg=cfg(__INTERNAL_USE_ONLY_NIGHTLY_FEATURES_IN_TESTS)"); + } + for version_cfg in version_cfgs { if rustc_version >= version_cfg.version { println!("cargo:rustc-cfg={}", version_cfg.cfg_name); diff --git a/src/lib.rs b/src/lib.rs index fbdba9d660..22b41ca44b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -173,9 +173,7 @@ // `unknown_lints` is `warn` by default and we deny warnings in CI, so without // this attribute, any unknown lint would cause a CI failure when testing with // our MSRV. -// -// TODO(#1201): Remove `unexpected_cfgs` -#![allow(unknown_lints, unexpected_cfgs)] +#![allow(unknown_lints)] #![deny(renamed_and_removed_lints)] #![deny( anonymous_parameters, @@ -8926,7 +8924,7 @@ mod tests { vector_signed_long, vector_unsigned_long ); - #[cfg(all(target_arch = "aarch64", zerocopy_aarch_simd))] + #[cfg(all(target_arch = "aarch64", zerocopy_aarch64_simd))] #[rustfmt::skip] test_simd_arch_mod!( aarch64, float32x2_t, float32x4_t, float64x1_t, float64x2_t, int8x8_t, int8x8x2_t,