diff --git a/serde_derive/build.rs b/serde_derive/build.rs deleted file mode 100644 index 1249dab59..000000000 --- a/serde_derive/build.rs +++ /dev/null @@ -1,38 +0,0 @@ -use std::env; -use std::process::Command; -use std::str; - -// The rustc-cfg strings below are *not* public API. Please let us know by -// opening a GitHub issue if your build environment requires some way to enable -// these cfgs other than by executing our build script. -fn main() { - println!("cargo:rerun-if-changed=build.rs"); - - let minor = match rustc_minor_version() { - Some(minor) => minor, - None => return, - }; - - // 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=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=no_ptr_addr_of"); - } -} - -fn rustc_minor_version() -> Option { - let rustc = env::var_os("RUSTC")?; - let output = Command::new(rustc).arg("--version").output().ok()?; - let version = str::from_utf8(&output.stdout).ok()?; - let mut pieces = version.split('.'); - if pieces.next() != Some("rustc 1") { - return None; - } - pieces.next()?.parse().ok() -} diff --git a/serde_derive/src/de.rs b/serde_derive/src/de.rs index 4d60d5a6f..63e839c43 100644 --- a/serde_derive/src/de.rs +++ b/serde_derive/src/de.rs @@ -69,8 +69,6 @@ pub fn expand_derive_deserialize( Ok(dummy::wrap_in_const( cont.attrs.custom_serde_path(), - "DESERIALIZE", - ident, impl_block, )) } diff --git a/serde_derive/src/dummy.rs b/serde_derive/src/dummy.rs index 2be502713..57e8eabf2 100644 --- a/serde_derive/src/dummy.rs +++ b/serde_derive/src/dummy.rs @@ -1,23 +1,11 @@ -use proc_macro2::{Ident, TokenStream}; -use quote::format_ident; +use proc_macro2::TokenStream; use syn; use try; -pub fn wrap_in_const( - serde_path: Option<&syn::Path>, - trait_: &str, - ty: &Ident, - code: TokenStream, -) -> TokenStream { +pub fn wrap_in_const(serde_path: Option<&syn::Path>, code: TokenStream) -> TokenStream { let try_replacement = try::replacement(); - let dummy_const = if cfg!(no_underscore_consts) { - format_ident!("_IMPL_{}_FOR_{}", trait_, unraw(ty)) - } else { - format_ident!("_") - }; - let use_serde = match serde_path { Some(path) => quote! { use #path as _serde; @@ -31,14 +19,10 @@ pub fn wrap_in_const( quote! { #[doc(hidden)] #[allow(non_upper_case_globals, unused_attributes, unused_qualifications)] - const #dummy_const: () = { + const _: () = { #use_serde #try_replacement #code }; } } - -fn unraw(ident: &Ident) -> String { - ident.to_string().trim_start_matches("r#").to_owned() -} diff --git a/serde_derive/src/pretend.rs b/serde_derive/src/pretend.rs index d7b953d63..7decbaa52 100644 --- a/serde_derive/src/pretend.rs +++ b/serde_derive/src/pretend.rs @@ -97,29 +97,14 @@ fn pretend_fields_used_struct_packed(cont: &Container, fields: &[Field]) -> Toke let members = fields.iter().map(|field| &field.member).collect::>(); - #[cfg(not(no_ptr_addr_of))] - { - quote! { - match _serde::__private::None::<&#type_ident #ty_generics> { - _serde::__private::Some(__v @ #type_ident { #(#members: _),* }) => { - #( - let _ = _serde::__private::ptr::addr_of!(__v.#members); - )* - } - _ => {} - } - } - } - - #[cfg(no_ptr_addr_of)] - { - let placeholders = (0usize..).map(|i| format_ident!("__v{}", i)); - - quote! { - match _serde::__private::None::<#type_ident #ty_generics> { - _serde::__private::Some(#type_ident { #(#members: #placeholders),* }) => {} - _ => {} + quote! { + match _serde::__private::None::<&#type_ident #ty_generics> { + _serde::__private::Some(__v @ #type_ident { #(#members: _),* }) => { + #( + let _ = _serde::__private::ptr::addr_of!(__v.#members); + )* } + _ => {} } } } diff --git a/serde_derive/src/ser.rs b/serde_derive/src/ser.rs index f223f713a..cd2992d72 100644 --- a/serde_derive/src/ser.rs +++ b/serde_derive/src/ser.rs @@ -59,8 +59,6 @@ pub fn expand_derive_serialize( Ok(dummy::wrap_in_const( cont.attrs.custom_serde_path(), - "SERIALIZE", - ident, impl_block, )) }