Merge pull request #2251 from taiki-e/derive-cfg

Invert build.rs cfgs in serde_derive
This commit is contained in:
David Tolnay 2022-07-20 09:25:14 -07:00 committed by GitHub
commit 5185487d73
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 9 deletions

View File

@ -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");
}
}

View File

@ -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 {

View File

@ -97,7 +97,7 @@ fn pretend_fields_used_struct_packed(cont: &Container, fields: &[Field]) -> Toke
let members = fields.iter().map(|field| &field.member).collect::<Vec<_>>();
#[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));