diff --git a/client/chain-spec/derive/src/impls.rs b/client/chain-spec/derive/src/impls.rs index 1b22f16581a79..ded961a6da815 100644 --- a/client/chain-spec/derive/src/impls.rs +++ b/client/chain-spec/derive/src/impls.rs @@ -64,7 +64,6 @@ pub fn extension_derive(ast: &DeriveInput) -> proc_macro::TokenStream { }) } - /// Implements required traits and creates `Fork` structs for `ChainSpec` custom parameter group. pub fn group_derive(ast: &DeriveInput) -> proc_macro::TokenStream { derive(ast, |crate_name, name, generics: &syn::Generics, field_names, field_types, _fields| { @@ -75,9 +74,27 @@ pub fn group_derive(ast: &DeriveInput) -> proc_macro::TokenStream { let to_fork = generate_base_to_fork(&fork_name, &field_names); let combine_with = generate_combine_with(&field_names); let to_base = generate_fork_to_base(name, &field_names); + let serde_crate_name = match proc_macro_crate::crate_name("serde") { + Ok(name) => Ident::new(&name.replace("-", "_"), Span::call_site()), + Err(e) => { + let err = Error::new( + Span::call_site(), + &format!("Could not find `serde` crate: {}", e), + ).to_compile_error(); + + return quote!( #err ).into(); + } + }; quote! { - #[derive(Debug, Clone, PartialEq, Serialize, Deserialize, ChainSpecExtension)] + #[derive( + Debug, + Clone, + PartialEq, + #serde_crate_name::Serialize, + #serde_crate_name::Deserialize, + ChainSpecExtension, + )] pub struct #fork_name #ty_generics #where_clause { #fork_fields } diff --git a/client/chain-spec/src/lib.rs b/client/chain-spec/src/lib.rs index 66bce2b1363c2..8901a9a682224 100644 --- a/client/chain-spec/src/lib.rs +++ b/client/chain-spec/src/lib.rs @@ -29,10 +29,9 @@ //! //! ```rust //! use std::collections::HashMap; -//! use serde::{Serialize, Deserialize}; //! use sc_chain_spec::{GenericChainSpec, ChainSpecExtension}; //! -//! #[derive(Clone, Debug, Serialize, Deserialize, ChainSpecExtension)] +//! #[derive(Clone, Debug, serde::Serialize, serde::Deserialize, ChainSpecExtension)] //! pub struct MyExtension { //! pub known_blocks: HashMap, //! } @@ -48,21 +47,20 @@ //! block number. //! //! ```rust -//! use serde::{Serialize, Deserialize}; //! use sc_chain_spec::{Forks, ChainSpecGroup, ChainSpecExtension, GenericChainSpec}; //! -//! #[derive(Clone, Debug, Serialize, Deserialize, ChainSpecGroup)] +//! #[derive(Clone, Debug, serde::Serialize, serde::Deserialize, ChainSpecGroup)] //! pub struct ClientParams { //! max_block_size: usize, //! max_extrinsic_size: usize, //! } //! -//! #[derive(Clone, Debug, Serialize, Deserialize, ChainSpecGroup)] +//! #[derive(Clone, Debug, serde::Serialize, serde::Deserialize, ChainSpecGroup)] //! pub struct PoolParams { //! max_transaction_size: usize, //! } //! -//! #[derive(Clone, Debug, Serialize, Deserialize, ChainSpecGroup, ChainSpecExtension)] +//! #[derive(Clone, Debug, serde::Serialize, serde::Deserialize, ChainSpecGroup, ChainSpecExtension)] //! pub struct Extension { //! pub client: ClientParams, //! pub pool: PoolParams,