Skip to content

Commit

Permalink
Merge pull request #2251 from taiki-e/derive-cfg
Browse files Browse the repository at this point in the history
Invert build.rs cfgs in serde_derive
  • Loading branch information
dtolnay authored Jul 20, 2022
2 parents a0eb83a + efaafd4 commit 5185487
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
8 changes: 4 additions & 4 deletions serde_derive/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}

Expand Down
6 changes: 3 additions & 3 deletions serde_derive/src/dummy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions serde_derive/src/pretend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand All @@ -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));

Expand Down

0 comments on commit 5185487

Please sign in to comment.