From efaafd44580dc4776b45b78152fa2c5333d8f0a6 Mon Sep 17 00:00:00 2001 From: Taiki Endo Date: Thu, 21 Jul 2022 01:15:37 +0900 Subject: [PATCH] Invert build.rs cfgs in serde_derive --- serde_derive/build.rs | 8 ++++---- serde_derive/src/dummy.rs | 6 +++--- serde_derive/src/pretend.rs | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/serde_derive/build.rs b/serde_derive/build.rs index d0c827a6..2aece046 100644 --- a/serde_derive/build.rs +++ b/serde_derive/build.rs @@ -13,14 +13,14 @@ fn main() { // Underscore const names stabilized in Rust 1.37: // https://blog.rust-lang.org/2019/08/15/Rust-1.37.0.html#using-unnamed-const-items-for-macros - if minor >= 37 { - println!("cargo:rustc-cfg=underscore_consts"); + if minor < 37 { + println!("cargo:rustc-cfg=no_underscore_consts"); } // The ptr::addr_of! macro stabilized in Rust 1.51: // https://blog.rust-lang.org/2021/03/25/Rust-1.51.0.html#stabilized-apis - if minor >= 51 { - println!("cargo:rustc-cfg=ptr_addr_of"); + if minor < 51 { + println!("cargo:rustc-cfg=no_ptr_addr_of"); } } diff --git a/serde_derive/src/dummy.rs b/serde_derive/src/dummy.rs index 29de2601..a02bd376 100644 --- a/serde_derive/src/dummy.rs +++ b/serde_derive/src/dummy.rs @@ -12,10 +12,10 @@ pub fn wrap_in_const( ) -> TokenStream { let try_replacement = try::replacement(); - let dummy_const = if cfg!(underscore_consts) { - format_ident!("_") - } else { + let dummy_const = if cfg!(no_underscore_consts) { format_ident!("_IMPL_{}_FOR_{}", trait_, unraw(ty)) + } else { + format_ident!("_") }; let use_serde = match serde_path { diff --git a/serde_derive/src/pretend.rs b/serde_derive/src/pretend.rs index 3af6a66f..d7b953d6 100644 --- a/serde_derive/src/pretend.rs +++ b/serde_derive/src/pretend.rs @@ -97,7 +97,7 @@ fn pretend_fields_used_struct_packed(cont: &Container, fields: &[Field]) -> Toke let members = fields.iter().map(|field| &field.member).collect::>(); - #[cfg(ptr_addr_of)] + #[cfg(not(no_ptr_addr_of))] { quote! { match _serde::__private::None::<&#type_ident #ty_generics> { @@ -111,7 +111,7 @@ fn pretend_fields_used_struct_packed(cont: &Container, fields: &[Field]) -> Toke } } - #[cfg(not(ptr_addr_of))] + #[cfg(no_ptr_addr_of)] { let placeholders = (0usize..).map(|i| format_ident!("__v{}", i));