mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-18 19:55:40 +00:00
Update syn, proc-macro2 and quote to 1.x (#4028)
This commit is contained in:
Generated
+12
-12
@@ -4112,8 +4112,8 @@ dependencies = [
|
|||||||
"criterion 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"criterion 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"parity-scale-codec 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
"parity-scale-codec 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"proc-macro-crate 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
"proc-macro-crate 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)",
|
"proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"quote 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)",
|
"quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"rustversion 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"rustversion 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"sr-primitives 2.0.0",
|
"sr-primitives 2.0.0",
|
||||||
"sr-version 2.0.0",
|
"sr-version 2.0.0",
|
||||||
@@ -4122,7 +4122,7 @@ dependencies = [
|
|||||||
"substrate-primitives 2.0.0",
|
"substrate-primitives 2.0.0",
|
||||||
"substrate-state-machine 2.0.0",
|
"substrate-state-machine 2.0.0",
|
||||||
"substrate-test-runtime-client 2.0.0",
|
"substrate-test-runtime-client 2.0.0",
|
||||||
"syn 0.15.44 (registry+https://github.com/rust-lang/crates.io-index)",
|
"syn 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"trybuild 1.0.17 (registry+https://github.com/rust-lang/crates.io-index)",
|
"trybuild 1.0.17 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -4761,11 +4761,11 @@ dependencies = [
|
|||||||
name = "srml-support-procedural"
|
name = "srml-support-procedural"
|
||||||
version = "2.0.0"
|
version = "2.0.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)",
|
"proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"quote 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)",
|
"quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"sr-api-macros 2.0.0",
|
"sr-api-macros 2.0.0",
|
||||||
"srml-support-procedural-tools 2.0.0",
|
"srml-support-procedural-tools 2.0.0",
|
||||||
"syn 0.15.44 (registry+https://github.com/rust-lang/crates.io-index)",
|
"syn 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -4773,19 +4773,19 @@ name = "srml-support-procedural-tools"
|
|||||||
version = "2.0.0"
|
version = "2.0.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro-crate 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
"proc-macro-crate 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)",
|
"proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"quote 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)",
|
"quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"srml-support-procedural-tools-derive 2.0.0",
|
"srml-support-procedural-tools-derive 2.0.0",
|
||||||
"syn 0.15.44 (registry+https://github.com/rust-lang/crates.io-index)",
|
"syn 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "srml-support-procedural-tools-derive"
|
name = "srml-support-procedural-tools-derive"
|
||||||
version = "2.0.0"
|
version = "2.0.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)",
|
"proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"quote 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)",
|
"quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"syn 0.15.44 (registry+https://github.com/rust-lang/crates.io-index)",
|
"syn 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|||||||
@@ -9,8 +9,8 @@ proc-macro = true
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
proc-macro-crate = "0.1.4"
|
proc-macro-crate = "0.1.4"
|
||||||
proc-macro2 = "1.0.4"
|
proc-macro2 = "1.0.6"
|
||||||
quote = "1.0.2"
|
quote = "1.0.2"
|
||||||
syn = "1.0.5"
|
syn = "1.0.7"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ proc-macro = true
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
quote = "1.0.2"
|
quote = "1.0.2"
|
||||||
syn = "1.0.5"
|
syn = "1.0.7"
|
||||||
proc-macro2 = "1.0"
|
proc-macro2 = "1.0"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
|
|||||||
@@ -8,9 +8,9 @@ edition = "2018"
|
|||||||
proc-macro = true
|
proc-macro = true
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
quote = "0.6.12"
|
quote = "1.0.2"
|
||||||
syn = { version = "0.15.44", features = [ "full", "fold", "extra-traits", "visit" ] }
|
syn = { version = "1.0.7", features = [ "full", "fold", "extra-traits", "visit" ] }
|
||||||
proc-macro2 = "0.4.27"
|
proc-macro2 = "1.0.6"
|
||||||
blake2-rfc = "0.2.18"
|
blake2-rfc = "0.2.18"
|
||||||
proc-macro-crate = "0.1.4"
|
proc-macro-crate = "0.1.4"
|
||||||
|
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ use crate::utils::{
|
|||||||
fold_fn_decl_for_client_side, unwrap_or_error, extract_parameter_names_types_and_borrows,
|
fold_fn_decl_for_client_side, unwrap_or_error, extract_parameter_names_types_and_borrows,
|
||||||
generate_native_call_generator_fn_name, return_type_extract_type,
|
generate_native_call_generator_fn_name, return_type_extract_type,
|
||||||
generate_method_runtime_api_impl_name, generate_call_api_at_fn_name, prefix_function_with_trait,
|
generate_method_runtime_api_impl_name, generate_call_api_at_fn_name, prefix_function_with_trait,
|
||||||
|
replace_wild_card_parameter_names,
|
||||||
};
|
};
|
||||||
|
|
||||||
use proc_macro2::{TokenStream, Span};
|
use proc_macro2::{TokenStream, Span};
|
||||||
@@ -27,9 +28,8 @@ use quote::quote;
|
|||||||
|
|
||||||
use syn::{
|
use syn::{
|
||||||
spanned::Spanned, parse_macro_input, parse::{Parse, ParseStream, Result, Error}, ReturnType,
|
spanned::Spanned, parse_macro_input, parse::{Parse, ParseStream, Result, Error}, ReturnType,
|
||||||
fold::{self, Fold}, parse_quote, ItemTrait, Generics, GenericParam, Attribute, FnArg,
|
fold::{self, Fold}, parse_quote, ItemTrait, Generics, GenericParam, Attribute, FnArg, Type,
|
||||||
visit::{Visit, self}, Pat, TraitBound, Meta, NestedMeta, Lit, TraitItem, Ident, Type,
|
visit::{Visit, self}, TraitBound, Meta, NestedMeta, Lit, TraitItem, Ident, TraitItemMethod,
|
||||||
TraitItemMethod
|
|
||||||
};
|
};
|
||||||
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
@@ -95,9 +95,9 @@ impl Parse for RuntimeApiDecls {
|
|||||||
fn extend_generics_with_block(generics: &mut Generics) {
|
fn extend_generics_with_block(generics: &mut Generics) {
|
||||||
let c = generate_crate_access(HIDDEN_INCLUDES_ID);
|
let c = generate_crate_access(HIDDEN_INCLUDES_ID);
|
||||||
|
|
||||||
generics.lt_token = Some(parse_quote!(<));
|
generics.lt_token = Some(Default::default());
|
||||||
generics.params.insert(0, parse_quote!( Block: #c::runtime_api::BlockT ));
|
generics.params.insert(0, parse_quote!( Block: #c::runtime_api::BlockT ));
|
||||||
generics.gt_token = Some(parse_quote!(>));
|
generics.gt_token = Some(Default::default());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Remove all attributes from the vector that are supported by us in the declaration of a runtime
|
/// Remove all attributes from the vector that are supported by us in the declaration of a runtime
|
||||||
@@ -182,7 +182,7 @@ fn generate_native_call_generators(decl: &ItemTrait) -> Result<TokenStream> {
|
|||||||
let crate_ = generate_crate_access(HIDDEN_INCLUDES_ID);
|
let crate_ = generate_crate_access(HIDDEN_INCLUDES_ID);
|
||||||
|
|
||||||
// Auxiliary function that is used to convert between types that use different block types.
|
// Auxiliary function that is used to convert between types that use different block types.
|
||||||
// The function expects that both a convertable by encoding the one and decoding the other.
|
// The function expects that both are convertible by encoding the one and decoding the other.
|
||||||
result.push(quote!(
|
result.push(quote!(
|
||||||
#[cfg(any(feature = "std", test))]
|
#[cfg(any(feature = "std", test))]
|
||||||
fn convert_between_block_types
|
fn convert_between_block_types
|
||||||
@@ -198,10 +198,10 @@ fn generate_native_call_generators(decl: &ItemTrait) -> Result<TokenStream> {
|
|||||||
|
|
||||||
// Generate a native call generator for each function of the given trait.
|
// Generate a native call generator for each function of the given trait.
|
||||||
for fn_ in fns {
|
for fn_ in fns {
|
||||||
let params = extract_parameter_names_types_and_borrows(&fn_.decl)?;
|
let params = extract_parameter_names_types_and_borrows(&fn_)?;
|
||||||
let trait_fn_name = &fn_.ident;
|
let trait_fn_name = &fn_.ident;
|
||||||
let fn_name = generate_native_call_generator_fn_name(&fn_.ident);
|
let fn_name = generate_native_call_generator_fn_name(&fn_.ident);
|
||||||
let output = return_type_replace_block_with_node_block(fn_.decl.output.clone());
|
let output = return_type_replace_block_with_node_block(fn_.output.clone());
|
||||||
let output_ty = return_type_extract_type(&output);
|
let output_ty = return_type_extract_type(&output);
|
||||||
let output = quote!( std::result::Result<#output_ty, String> );
|
let output = quote!( std::result::Result<#output_ty, String> );
|
||||||
|
|
||||||
@@ -217,7 +217,7 @@ fn generate_native_call_generators(decl: &ItemTrait) -> Result<TokenStream> {
|
|||||||
});
|
});
|
||||||
// Same as for the input types, we need to check if we also need to convert the output,
|
// Same as for the input types, we need to check if we also need to convert the output,
|
||||||
// before returning it.
|
// before returning it.
|
||||||
let output_conversion = if return_type_is_using_block(&fn_.decl.output) {
|
let output_conversion = if return_type_is_using_block(&fn_.output) {
|
||||||
quote!(
|
quote!(
|
||||||
convert_between_block_types(
|
convert_between_block_types(
|
||||||
&res,
|
&res,
|
||||||
@@ -234,22 +234,21 @@ fn generate_native_call_generators(decl: &ItemTrait) -> Result<TokenStream> {
|
|||||||
// the user. Otherwise if it is not using the block, we don't need to add anything.
|
// the user. Otherwise if it is not using the block, we don't need to add anything.
|
||||||
let input_borrows = params
|
let input_borrows = params
|
||||||
.iter()
|
.iter()
|
||||||
.map(|v| if type_is_using_block(&v.1) { v.2.clone() } else { quote!() });
|
.map(|v| if type_is_using_block(&v.1) { v.2.clone() } else { None });
|
||||||
|
|
||||||
// Replace all `Block` with `NodeBlock`, add `'a` lifetime to references and collect
|
// Replace all `Block` with `NodeBlock`, add `'a` lifetime to references and collect
|
||||||
// all the function inputs.
|
// all the function inputs.
|
||||||
let fn_inputs = fn_
|
let fn_inputs = fn_
|
||||||
.decl
|
|
||||||
.inputs
|
.inputs
|
||||||
.iter()
|
.iter()
|
||||||
.map(|v| fn_arg_replace_block_with_node_block(v.clone()))
|
.map(|v| fn_arg_replace_block_with_node_block(v.clone()))
|
||||||
.map(|v| match v {
|
.map(|v| match v {
|
||||||
FnArg::Captured(ref arg) => {
|
FnArg::Typed(ref arg) => {
|
||||||
let mut arg = arg.clone();
|
let mut arg = arg.clone();
|
||||||
if let Type::Reference(ref mut r) = arg.ty {
|
if let Type::Reference(ref mut r) = *arg.ty {
|
||||||
r.lifetime = Some(parse_quote!( 'a ));
|
r.lifetime = Some(parse_quote!( 'a ));
|
||||||
}
|
}
|
||||||
FnArg::Captured(arg)
|
FnArg::Typed(arg)
|
||||||
},
|
},
|
||||||
r => r.clone(),
|
r => r.clone(),
|
||||||
});
|
});
|
||||||
@@ -310,15 +309,15 @@ fn parse_renamed_attribute(renamed: &Attribute) -> Result<(String, u32)> {
|
|||||||
} else {
|
} else {
|
||||||
let mut itr = list.nested.iter();
|
let mut itr = list.nested.iter();
|
||||||
let old_name = match itr.next() {
|
let old_name = match itr.next() {
|
||||||
Some(NestedMeta::Literal(Lit::Str(i))) => {
|
Some(NestedMeta::Lit(Lit::Str(i))) => {
|
||||||
i.value()
|
i.value()
|
||||||
},
|
},
|
||||||
_ => return err,
|
_ => return err,
|
||||||
};
|
};
|
||||||
|
|
||||||
let version = match itr.next() {
|
let version = match itr.next() {
|
||||||
Some(NestedMeta::Literal(Lit::Int(i))) => {
|
Some(NestedMeta::Lit(Lit::Int(i))) => {
|
||||||
i.value() as u32
|
i.base10_parse()?
|
||||||
},
|
},
|
||||||
_ => return err,
|
_ => return err,
|
||||||
};
|
};
|
||||||
@@ -488,6 +487,8 @@ fn generate_runtime_decls(decls: &[ItemTrait]) -> TokenStream {
|
|||||||
if remove_supported_attributes(&mut method.attrs).contains_key(CHANGED_IN_ATTRIBUTE) {
|
if remove_supported_attributes(&mut method.attrs).contains_key(CHANGED_IN_ATTRIBUTE) {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
|
// Make sure we replace all the wild card parameter names.
|
||||||
|
replace_wild_card_parameter_names(&mut method.sig);
|
||||||
Some(TraitItem::Method(method.clone()))
|
Some(TraitItem::Method(method.clone()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -565,7 +566,7 @@ impl<'a> ToClientSideDecl<'a> {
|
|||||||
let context_arg: syn::FnArg = parse_quote!( context: #crate_::runtime_api::ExecutionContext );
|
let context_arg: syn::FnArg = parse_quote!( context: #crate_::runtime_api::ExecutionContext );
|
||||||
let mut fn_decl_ctx = self.create_method_decl(method, quote!( context ));
|
let mut fn_decl_ctx = self.create_method_decl(method, quote!( context ));
|
||||||
fn_decl_ctx.sig.ident = Ident::new(&format!("{}_with_context", &fn_decl_ctx.sig.ident), Span::call_site());
|
fn_decl_ctx.sig.ident = Ident::new(&format!("{}_with_context", &fn_decl_ctx.sig.ident), Span::call_site());
|
||||||
fn_decl_ctx.sig.decl.inputs.insert(2, context_arg);
|
fn_decl_ctx.sig.inputs.insert(2, context_arg);
|
||||||
|
|
||||||
fn_decl_ctx
|
fn_decl_ctx
|
||||||
}
|
}
|
||||||
@@ -577,12 +578,12 @@ impl<'a> ToClientSideDecl<'a> {
|
|||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
let fn_decl = &method.sig.decl;
|
let fn_sig = &method.sig;
|
||||||
let ret_type = return_type_extract_type(&fn_decl.output);
|
let ret_type = return_type_extract_type(&fn_sig.output);
|
||||||
|
|
||||||
// Get types and if the value is borrowed from all parameters.
|
// Get types and if the value is borrowed from all parameters.
|
||||||
// If there is an error, we push it as the block to the user.
|
// If there is an error, we push it as the block to the user.
|
||||||
let param_types = match extract_parameter_names_types_and_borrows(fn_decl) {
|
let param_types = match extract_parameter_names_types_and_borrows(fn_sig) {
|
||||||
Ok(res) => res.into_iter().map(|v| {
|
Ok(res) => res.into_iter().map(|v| {
|
||||||
let ty = v.1;
|
let ty = v.1;
|
||||||
let borrow = v.2;
|
let borrow = v.2;
|
||||||
@@ -614,8 +615,12 @@ impl<'a> ToClientSideDecl<'a> {
|
|||||||
/// Takes the method declared by the user and creates the declaration we require for the runtime
|
/// Takes the method declared by the user and creates the declaration we require for the runtime
|
||||||
/// api client side. This method will call by default the `method_runtime_api_impl` for doing
|
/// api client side. This method will call by default the `method_runtime_api_impl` for doing
|
||||||
/// the actual call into the runtime.
|
/// the actual call into the runtime.
|
||||||
fn create_method_decl(&mut self, mut method: TraitItemMethod, context: TokenStream) -> TraitItemMethod {
|
fn create_method_decl(
|
||||||
let params = match extract_parameter_names_types_and_borrows(&method.sig.decl) {
|
&mut self,
|
||||||
|
mut method: TraitItemMethod,
|
||||||
|
context: TokenStream,
|
||||||
|
) -> TraitItemMethod {
|
||||||
|
let params = match extract_parameter_names_types_and_borrows(&method.sig) {
|
||||||
Ok(res) => res.into_iter().map(|v| v.0).collect::<Vec<_>>(),
|
Ok(res) => res.into_iter().map(|v| v.0).collect::<Vec<_>>(),
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
self.errors.push(e.to_compile_error());
|
self.errors.push(e.to_compile_error());
|
||||||
@@ -623,13 +628,10 @@ impl<'a> ToClientSideDecl<'a> {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
let params2 = params.clone();
|
let params2 = params.clone();
|
||||||
let ret_type = return_type_extract_type(&method.sig.decl.output);
|
let ret_type = return_type_extract_type(&method.sig.output);
|
||||||
|
|
||||||
|
fold_fn_decl_for_client_side(&mut method.sig, &self.block_id, &self.crate_);
|
||||||
|
|
||||||
method.sig.decl = fold_fn_decl_for_client_side(
|
|
||||||
method.sig.decl.clone(),
|
|
||||||
&self.block_id,
|
|
||||||
&self.crate_
|
|
||||||
);
|
|
||||||
let name_impl = generate_method_runtime_api_impl_name(&self.trait_, &method.sig.ident);
|
let name_impl = generate_method_runtime_api_impl_name(&self.trait_, &method.sig.ident);
|
||||||
let crate_ = self.crate_;
|
let crate_ = self.crate_;
|
||||||
|
|
||||||
@@ -650,7 +652,7 @@ impl<'a> ToClientSideDecl<'a> {
|
|||||||
|
|
||||||
let ident = Ident::new(
|
let ident = Ident::new(
|
||||||
&format!("{}_before_version_{}", method.sig.ident, version),
|
&format!("{}_before_version_{}", method.sig.ident, version),
|
||||||
method.sig.ident.span()
|
method.sig.ident.span(),
|
||||||
);
|
);
|
||||||
method.sig.ident = ident;
|
method.sig.ident = ident;
|
||||||
method.attrs.push(parse_quote!( #[deprecated] ));
|
method.attrs.push(parse_quote!( #[deprecated] ));
|
||||||
@@ -674,22 +676,26 @@ impl<'a> ToClientSideDecl<'a> {
|
|||||||
let runtime_api_impl_params_encoded =
|
let runtime_api_impl_params_encoded =
|
||||||
#crate_::runtime_api::Encode::encode(&( #( &#params ),* ));
|
#crate_::runtime_api::Encode::encode(&( #( &#params ),* ));
|
||||||
|
|
||||||
self.#name_impl(at, #context, #param_tuple, runtime_api_impl_params_encoded)
|
self.#name_impl(
|
||||||
.and_then(|r|
|
__runtime_api_at_param__,
|
||||||
match r {
|
#context,
|
||||||
#crate_::runtime_api::NativeOrEncoded::Native(n) => {
|
#param_tuple,
|
||||||
#native_handling
|
runtime_api_impl_params_encoded,
|
||||||
},
|
).and_then(|r|
|
||||||
#crate_::runtime_api::NativeOrEncoded::Encoded(r) => {
|
match r {
|
||||||
<#ret_type as #crate_::runtime_api::Decode>::decode(&mut &r[..])
|
#crate_::runtime_api::NativeOrEncoded::Native(n) => {
|
||||||
.map_err(|err|
|
#native_handling
|
||||||
#crate_::error::Error::CallResultDecode(
|
},
|
||||||
#function_name, err
|
#crate_::runtime_api::NativeOrEncoded::Encoded(r) => {
|
||||||
).into()
|
<#ret_type as #crate_::runtime_api::Decode>::decode(&mut &r[..])
|
||||||
)
|
.map_err(|err|
|
||||||
}
|
#crate_::error::Error::CallResultDecode(
|
||||||
|
#function_name, err
|
||||||
|
).into()
|
||||||
|
)
|
||||||
}
|
}
|
||||||
)
|
}
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@@ -745,15 +751,12 @@ fn parse_runtime_api_version(version: &Attribute) -> Result<u64> {
|
|||||||
|
|
||||||
match meta {
|
match meta {
|
||||||
Meta::List(list) => {
|
Meta::List(list) => {
|
||||||
if list.nested.len() > 1 && list.nested.is_empty() {
|
if list.nested.len() != 1 {
|
||||||
err
|
err
|
||||||
|
} else if let Some(NestedMeta::Lit(Lit::Int(i))) = list.nested.first() {
|
||||||
|
i.base10_parse()
|
||||||
} else {
|
} else {
|
||||||
match list.nested.first().as_ref().map(|v| v.value()) {
|
err
|
||||||
Some(NestedMeta::Literal(Lit::Int(i))) => {
|
|
||||||
Ok(i.value())
|
|
||||||
},
|
|
||||||
_ => err,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
_ => err,
|
_ => err,
|
||||||
@@ -848,32 +851,8 @@ struct CheckTraitDecl {
|
|||||||
|
|
||||||
impl<'ast> Visit<'ast> for CheckTraitDecl {
|
impl<'ast> Visit<'ast> for CheckTraitDecl {
|
||||||
fn visit_fn_arg(&mut self, input: &'ast FnArg) {
|
fn visit_fn_arg(&mut self, input: &'ast FnArg) {
|
||||||
match input {
|
if let FnArg::Receiver(_) = input {
|
||||||
FnArg::Captured(ref arg) => {
|
self.errors.push(Error::new(input.span(), "`self` as argument not supported."))
|
||||||
match arg.pat {
|
|
||||||
Pat::Ident(ref pat) if pat.ident == "at" => {
|
|
||||||
self.errors.push(
|
|
||||||
Error::new(
|
|
||||||
pat.span(),
|
|
||||||
"`decl_runtime_apis!` adds automatically a parameter \
|
|
||||||
`at: &BlockId<Block>`. Please rename/remove your parameter."
|
|
||||||
)
|
|
||||||
)
|
|
||||||
},
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
FnArg::SelfRef(_) | FnArg::SelfValue(_) => {
|
|
||||||
self.errors.push(Error::new(input.span(), "Self values are not supported."))
|
|
||||||
}
|
|
||||||
_ => {
|
|
||||||
self.errors.push(
|
|
||||||
Error::new(
|
|
||||||
input.span(),
|
|
||||||
"Only function arguments in the form `pat: type` are supported."
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
visit::visit_fn_arg(self, input);
|
visit::visit_fn_arg(self, input);
|
||||||
@@ -897,7 +876,7 @@ impl<'ast> Visit<'ast> for CheckTraitDecl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn visit_trait_bound(&mut self, input: &'ast TraitBound) {
|
fn visit_trait_bound(&mut self, input: &'ast TraitBound) {
|
||||||
if let Some(last_ident) = input.path.segments.last().map(|v| &v.value().ident) {
|
if let Some(last_ident) = input.path.segments.last().map(|v| &v.ident) {
|
||||||
if last_ident == "BlockT" || last_ident == BLOCK_GENERIC_IDENT {
|
if last_ident == "BlockT" || last_ident == BLOCK_GENERIC_IDENT {
|
||||||
self.errors.push(
|
self.errors.push(
|
||||||
Error::new(
|
Error::new(
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ use proc_macro2::{Span, TokenStream};
|
|||||||
use quote::quote;
|
use quote::quote;
|
||||||
|
|
||||||
use syn::{
|
use syn::{
|
||||||
spanned::Spanned, parse_macro_input, Ident, Type, ItemImpl, MethodSig, Path,
|
spanned::Spanned, parse_macro_input, Ident, Type, ItemImpl, Path, Signature,
|
||||||
ImplItem, parse::{Parse, ParseStream, Result, Error}, PathArguments, GenericArgument, TypePath,
|
ImplItem, parse::{Parse, ParseStream, Result, Error}, PathArguments, GenericArgument, TypePath,
|
||||||
fold::{self, Fold}, parse_quote
|
fold::{self, Fold}, parse_quote
|
||||||
};
|
};
|
||||||
@@ -56,12 +56,12 @@ impl Parse for RuntimeApiImpls {
|
|||||||
/// Generates the call to the implementation of the requested function.
|
/// Generates the call to the implementation of the requested function.
|
||||||
/// The generated code includes decoding of the input arguments and encoding of the output.
|
/// The generated code includes decoding of the input arguments and encoding of the output.
|
||||||
fn generate_impl_call(
|
fn generate_impl_call(
|
||||||
signature: &MethodSig,
|
signature: &Signature,
|
||||||
runtime: &Type,
|
runtime: &Type,
|
||||||
input: &Ident,
|
input: &Ident,
|
||||||
impl_trait: &Path
|
impl_trait: &Path
|
||||||
) -> Result<TokenStream> {
|
) -> Result<TokenStream> {
|
||||||
let params = extract_parameter_names_types_and_borrows(&signature.decl)?;
|
let params = extract_parameter_names_types_and_borrows(signature)?;
|
||||||
|
|
||||||
let c = generate_crate_access(HIDDEN_INCLUDES_ID);
|
let c = generate_crate_access(HIDDEN_INCLUDES_ID);
|
||||||
let c_iter = iter::repeat(&c);
|
let c_iter = iter::repeat(&c);
|
||||||
@@ -110,23 +110,20 @@ fn extract_impl_trait<'a>(impl_: &'a ItemImpl) -> Result<&'a Path> {
|
|||||||
/// Extracts the runtime block identifier.
|
/// Extracts the runtime block identifier.
|
||||||
fn extract_runtime_block_ident(trait_: &Path) -> Result<&TypePath> {
|
fn extract_runtime_block_ident(trait_: &Path) -> Result<&TypePath> {
|
||||||
let span = trait_.span();
|
let span = trait_.span();
|
||||||
let segment = trait_
|
let generics = trait_
|
||||||
.segments
|
.segments
|
||||||
.last()
|
.last()
|
||||||
.ok_or_else(
|
.ok_or_else(|| Error::new(span, "Empty path not supported"))?;
|
||||||
|| Error::new(span, "Empty path not supported")
|
|
||||||
)?;
|
|
||||||
let generics = segment.value();
|
|
||||||
|
|
||||||
match &generics.arguments {
|
match &generics.arguments {
|
||||||
PathArguments::AngleBracketed(ref args) => {
|
PathArguments::AngleBracketed(ref args) => {
|
||||||
args.args.first().and_then(|v| match v.value() {
|
args.args.first().and_then(|v| match v {
|
||||||
GenericArgument::Type(Type::Path(block)) => Some(block),
|
GenericArgument::Type(Type::Path(ref block)) => Some(block),
|
||||||
_ => None
|
_ => None
|
||||||
}).ok_or_else(|| Error::new(args.span(), "Missing `Block` generic parameter."))
|
}).ok_or_else(|| Error::new(args.span(), "Missing `Block` generic parameter."))
|
||||||
},
|
},
|
||||||
PathArguments::None => {
|
PathArguments::None => {
|
||||||
let span = trait_.segments.last().as_ref().unwrap().value().span();
|
let span = trait_.segments.last().as_ref().unwrap().span();
|
||||||
Err(Error::new(span, "Missing `Block` generic parameter."))
|
Err(Error::new(span, "Missing `Block` generic parameter."))
|
||||||
},
|
},
|
||||||
PathArguments::Parenthesized(_) => {
|
PathArguments::Parenthesized(_) => {
|
||||||
@@ -149,7 +146,6 @@ fn generate_impl_calls(
|
|||||||
.segments
|
.segments
|
||||||
.last()
|
.last()
|
||||||
.ok_or_else(|| Error::new(impl_trait_path.span(), "Empty trait path not possible!"))?
|
.ok_or_else(|| Error::new(impl_trait_path.span(), "Empty trait path not possible!"))?
|
||||||
.value()
|
|
||||||
.ident;
|
.ident;
|
||||||
|
|
||||||
for item in &impl_.items {
|
for item in &impl_.items {
|
||||||
@@ -363,7 +359,7 @@ fn generate_runtime_api_base_structures(impls: &[ItemImpl]) -> Result<TokenStrea
|
|||||||
res
|
res
|
||||||
}
|
}
|
||||||
|
|
||||||
fn commit_on_ok<R, E>(&self, res: &::std::result::Result<R, E>) {
|
fn commit_on_ok<R, E>(&self, res: &std::result::Result<R, E>) {
|
||||||
if *self.commit_on_success.borrow() {
|
if *self.commit_on_success.borrow() {
|
||||||
if res.is_err() {
|
if res.is_err() {
|
||||||
self.changes.borrow_mut().discard_prospective();
|
self.changes.borrow_mut().discard_prospective();
|
||||||
@@ -385,7 +381,6 @@ fn extend_with_runtime_decl_path(mut trait_: Path) -> Path {
|
|||||||
.last()
|
.last()
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.expect("Trait path should always contain at least one item; qed")
|
.expect("Trait path should always contain at least one item; qed")
|
||||||
.value()
|
|
||||||
.ident;
|
.ident;
|
||||||
|
|
||||||
generate_runtime_mod_name_for_trait(trait_name)
|
generate_runtime_mod_name_for_trait(trait_name)
|
||||||
@@ -455,16 +450,16 @@ impl<'a> Fold for ApiRuntimeImplToApiRuntimeApiImpl<'a> {
|
|||||||
let block_id = self.node_block_id;
|
let block_id = self.node_block_id;
|
||||||
|
|
||||||
// Generate the access to the native parameters
|
// Generate the access to the native parameters
|
||||||
let param_tuple_access = if input.sig.decl.inputs.len() == 1 {
|
let param_tuple_access = if input.sig.inputs.len() == 1 {
|
||||||
vec![ quote!( p ) ]
|
vec![ quote!( p ) ]
|
||||||
} else {
|
} else {
|
||||||
input.sig.decl.inputs.iter().enumerate().map(|(i, _)| {
|
input.sig.inputs.iter().enumerate().map(|(i, _)| {
|
||||||
let i = syn::Index::from(i);
|
let i = syn::Index::from(i);
|
||||||
quote!( p.#i )
|
quote!( p.#i )
|
||||||
}).collect::<Vec<_>>()
|
}).collect::<Vec<_>>()
|
||||||
};
|
};
|
||||||
|
|
||||||
let (param_types, error) = match extract_parameter_names_types_and_borrows(&input.sig.decl) {
|
let (param_types, error) = match extract_parameter_names_types_and_borrows(&input.sig) {
|
||||||
Ok(res) => (
|
Ok(res) => (
|
||||||
res.into_iter().map(|v| {
|
res.into_iter().map(|v| {
|
||||||
let ty = v.1;
|
let ty = v.1;
|
||||||
@@ -476,18 +471,23 @@ impl<'a> Fold for ApiRuntimeImplToApiRuntimeApiImpl<'a> {
|
|||||||
Err(e) => (Vec::new(), Some(e.to_compile_error())),
|
Err(e) => (Vec::new(), Some(e.to_compile_error())),
|
||||||
};
|
};
|
||||||
|
|
||||||
let context_arg: syn::FnArg = parse_quote!( context: #crate_::runtime_api::ExecutionContext );
|
|
||||||
|
|
||||||
// Rewrite the input parameters.
|
// Rewrite the input parameters.
|
||||||
input.sig.decl.inputs = parse_quote! {
|
input.sig.inputs = parse_quote! {
|
||||||
&self, at: &#block_id, #context_arg, params: Option<( #( #param_types ),* )>, params_encoded: Vec<u8>
|
&self,
|
||||||
|
at: &#block_id,
|
||||||
|
context: #crate_::runtime_api::ExecutionContext,
|
||||||
|
params: Option<( #( #param_types ),* )>,
|
||||||
|
params_encoded: Vec<u8>,
|
||||||
};
|
};
|
||||||
|
|
||||||
input.sig.ident = generate_method_runtime_api_impl_name(&self.impl_trait, &input.sig.ident);
|
input.sig.ident = generate_method_runtime_api_impl_name(
|
||||||
let ret_type = return_type_extract_type(&input.sig.decl.output);
|
&self.impl_trait,
|
||||||
|
&input.sig.ident,
|
||||||
|
);
|
||||||
|
let ret_type = return_type_extract_type(&input.sig.output);
|
||||||
|
|
||||||
// Generate the correct return type.
|
// Generate the correct return type.
|
||||||
input.sig.decl.output = parse_quote!(
|
input.sig.output = parse_quote!(
|
||||||
-> #crate_::error::Result<#crate_::runtime_api::NativeOrEncoded<#ret_type>>
|
-> #crate_::error::Result<#crate_::runtime_api::NativeOrEncoded<#ret_type>>
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -495,7 +495,7 @@ impl<'a> Fold for ApiRuntimeImplToApiRuntimeApiImpl<'a> {
|
|||||||
parse_quote!(
|
parse_quote!(
|
||||||
{
|
{
|
||||||
// Get the error to the user (if we have one).
|
// Get the error to the user (if we have one).
|
||||||
#( #error )*
|
#error
|
||||||
|
|
||||||
self.call_api_at(
|
self.call_api_at(
|
||||||
|call_runtime_at, core_api, changes, initialized_block, recorder| {
|
|call_runtime_at, core_api, changes, initialized_block, recorder| {
|
||||||
@@ -556,7 +556,7 @@ fn generate_api_impl_for_runtime_api(impls: &[ItemImpl]) -> Result<TokenStream>
|
|||||||
.segments
|
.segments
|
||||||
.last()
|
.last()
|
||||||
.ok_or_else(|| Error::new(impl_trait_path.span(), "Empty trait path not possible!"))?
|
.ok_or_else(|| Error::new(impl_trait_path.span(), "Empty trait path not possible!"))?
|
||||||
.into_value();
|
.clone();
|
||||||
let runtime_block = extract_runtime_block_ident(impl_trait_path)?;
|
let runtime_block = extract_runtime_block_ident(impl_trait_path)?;
|
||||||
let (node_block, node_block_id) = generate_node_block_and_block_id_ty(&impl_.self_ty);
|
let (node_block, node_block_id) = generate_node_block_and_block_id_ty(&impl_.self_ty);
|
||||||
let runtime_type = &impl_.self_ty;
|
let runtime_type = &impl_.self_ty;
|
||||||
|
|||||||
@@ -15,9 +15,15 @@
|
|||||||
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
|
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use proc_macro2::{TokenStream, Span};
|
use proc_macro2::{TokenStream, Span};
|
||||||
use syn::{Result, Ident, FnDecl, parse_quote, Type, Pat, spanned::Spanned, FnArg, Error};
|
|
||||||
|
use syn::{
|
||||||
|
Result, Ident, Signature, parse_quote, Type, Pat, spanned::Spanned, FnArg, Error, token::And,
|
||||||
|
};
|
||||||
|
|
||||||
use quote::quote;
|
use quote::quote;
|
||||||
|
|
||||||
use std::env;
|
use std::env;
|
||||||
|
|
||||||
use proc_macro_crate::crate_name;
|
use proc_macro_crate::crate_name;
|
||||||
|
|
||||||
/// Unwrap the given result, if it is an error, `compile_error!` will be generated.
|
/// Unwrap the given result, if it is an error, `compile_error!` will be generated.
|
||||||
@@ -82,23 +88,33 @@ pub fn return_type_extract_type(rt: &syn::ReturnType) -> Type {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Fold the given `FnDecl` to make it usable on the client side.
|
/// Replace the `_` (wild card) parameter names in the given signature with unique identifiers.
|
||||||
|
pub fn replace_wild_card_parameter_names(input: &mut Signature) {
|
||||||
|
let mut generated_pattern_counter = 0;
|
||||||
|
input.inputs.iter_mut().for_each(|arg| if let FnArg::Typed(arg) = arg {
|
||||||
|
arg.pat = Box::new(
|
||||||
|
generate_unique_pattern((*arg.pat).clone(), &mut generated_pattern_counter),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Fold the given `Signature` to make it usable on the client side.
|
||||||
pub fn fold_fn_decl_for_client_side(
|
pub fn fold_fn_decl_for_client_side(
|
||||||
mut input: FnDecl,
|
input: &mut Signature,
|
||||||
block_id: &TokenStream,
|
block_id: &TokenStream,
|
||||||
crate_: &TokenStream
|
crate_: &TokenStream,
|
||||||
) -> FnDecl {
|
) {
|
||||||
|
replace_wild_card_parameter_names(input);
|
||||||
|
|
||||||
// Add `&self, at:& BlockId` as parameters to each function at the beginning.
|
// Add `&self, at:& BlockId` as parameters to each function at the beginning.
|
||||||
input.inputs.insert(0, parse_quote!( at: &#block_id ));
|
input.inputs.insert(0, parse_quote!( __runtime_api_at_param__: &#block_id ));
|
||||||
input.inputs.insert(0, parse_quote!( &self ));
|
input.inputs.insert(0, parse_quote!( &self ));
|
||||||
|
|
||||||
// Wrap the output in a `Result`
|
// Wrap the output in a `Result`
|
||||||
input.output = {
|
input.output = {
|
||||||
let ty = return_type_extract_type(&input.output);
|
let ty = return_type_extract_type(&input.output);
|
||||||
parse_quote!( -> ::std::result::Result<#ty, #crate_::error::Error> )
|
parse_quote!( -> std::result::Result<#ty, #crate_::error::Error> )
|
||||||
};
|
};
|
||||||
|
|
||||||
input
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Generate an unique pattern based on the given counter, if the given pattern is a `_`.
|
/// Generate an unique pattern based on the given counter, if the given pattern is a `_`.
|
||||||
@@ -106,8 +122,8 @@ pub fn generate_unique_pattern(pat: Pat, counter: &mut u32) -> Pat {
|
|||||||
match pat {
|
match pat {
|
||||||
Pat::Wild(_) => {
|
Pat::Wild(_) => {
|
||||||
let generated_name = Ident::new(
|
let generated_name = Ident::new(
|
||||||
&format!("runtime_api_generated_name_{}", counter),
|
&format!("__runtime_api_generated_name_{}__", counter),
|
||||||
pat.span()
|
pat.span(),
|
||||||
);
|
);
|
||||||
*counter += 1;
|
*counter += 1;
|
||||||
|
|
||||||
@@ -115,38 +131,31 @@ pub fn generate_unique_pattern(pat: Pat, counter: &mut u32) -> Pat {
|
|||||||
},
|
},
|
||||||
_ => pat,
|
_ => pat,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Extracts the name, the type and `&` or ``(if it is a reference or not)
|
/// Extracts the name, the type and `&` or ``(if it is a reference or not)
|
||||||
/// for each parameter in the given function declaration.
|
/// for each parameter in the given function signature.
|
||||||
pub fn extract_parameter_names_types_and_borrows(fn_decl: &FnDecl)
|
pub fn extract_parameter_names_types_and_borrows(sig: &Signature)
|
||||||
-> Result<Vec<(Pat, Type, TokenStream)>>
|
-> Result<Vec<(Pat, Type, Option<And>)>>
|
||||||
{
|
{
|
||||||
let mut result = Vec::new();
|
let mut result = Vec::new();
|
||||||
let mut generated_pattern_counter = 0;
|
let mut generated_pattern_counter = 0;
|
||||||
for input in fn_decl.inputs.iter() {
|
for input in sig.inputs.iter() {
|
||||||
match input {
|
match input {
|
||||||
FnArg::Captured(arg) => {
|
FnArg::Typed(arg) => {
|
||||||
let (ty, borrow) = match &arg.ty {
|
let (ty, borrow) = match &*arg.ty {
|
||||||
Type::Reference(t) => {
|
Type::Reference(t) => {
|
||||||
let ty = &t.elem;
|
((*t.elem).clone(), Some(t.and_token))
|
||||||
(parse_quote!( #ty ), quote!( & ))
|
|
||||||
},
|
},
|
||||||
t => { (t.clone(), quote!()) },
|
t => { (t.clone(), None) },
|
||||||
};
|
};
|
||||||
|
|
||||||
let name =
|
let name =
|
||||||
generate_unique_pattern(arg.pat.clone(), &mut generated_pattern_counter);
|
generate_unique_pattern((*arg.pat).clone(), &mut generated_pattern_counter);
|
||||||
result.push((name, ty, borrow));
|
result.push((name, ty, borrow));
|
||||||
},
|
},
|
||||||
_ => {
|
FnArg::Receiver(_) => {
|
||||||
return Err(
|
return Err(Error::new(input.span(), "`self` parameter not supported!"))
|
||||||
Error::new(
|
|
||||||
input.span(),
|
|
||||||
"Only function arguments with the following \
|
|
||||||
pattern are accepted: `name: type`!"
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ decl_runtime_apis! {
|
|||||||
fn something_with_block(block: Block) -> Block;
|
fn something_with_block(block: Block) -> Block;
|
||||||
fn function_with_two_args(data: u64, block: Block);
|
fn function_with_two_args(data: u64, block: Block);
|
||||||
fn same_name();
|
fn same_name();
|
||||||
|
fn wild_card(_: u32);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[api_version(2)]
|
#[api_version(2)]
|
||||||
@@ -58,6 +59,8 @@ impl_runtime_apis! {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn same_name() {}
|
fn same_name() {}
|
||||||
|
|
||||||
|
fn wild_card(_: u32) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl self::ApiWithCustomVersion<Block> for Runtime {
|
impl self::ApiWithCustomVersion<Block> for Runtime {
|
||||||
|
|||||||
@@ -1,9 +0,0 @@
|
|||||||
use client::decl_runtime_apis;
|
|
||||||
|
|
||||||
decl_runtime_apis! {
|
|
||||||
pub trait Api {
|
|
||||||
fn test(at: u64);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {}
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
error: `decl_runtime_apis!` adds automatically a parameter `at: &BlockId<Block>`. Please rename/remove your parameter.
|
|
||||||
--> $DIR/adding_at_parameter.rs:5:11
|
|
||||||
|
|
|
||||||
5 | fn test(at: u64);
|
|
||||||
| ^^
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
error: Self values are not supported.
|
error: `self` as argument not supported.
|
||||||
--> $DIR/adding_self_parameter.rs:5:11
|
--> $DIR/adding_self_parameter.rs:5:11
|
||||||
|
|
|
|
||||||
5 | fn test(&self);
|
5 | fn test(&self);
|
||||||
|
|||||||
@@ -40,3 +40,15 @@ error[E0308]: mismatched types
|
|||||||
|
|
|
|
||||||
= note: expected type `u64`
|
= note: expected type `u64`
|
||||||
found type `&u64`
|
found type `&u64`
|
||||||
|
|
||||||
|
error[E0308]: mismatched types
|
||||||
|
--> $DIR/type_reference_in_impl_runtime_apis_call.rs:20:11
|
||||||
|
|
|
||||||
|
20 | fn test(data: &u64) {
|
||||||
|
| ^^^^^^^
|
||||||
|
| |
|
||||||
|
| expected u64, found &u64
|
||||||
|
| help: consider removing the borrow: `data`
|
||||||
|
|
|
||||||
|
= note: expected type `u64`
|
||||||
|
found type `&u64`
|
||||||
|
|||||||
@@ -8,9 +8,9 @@ edition = "2018"
|
|||||||
proc-macro = true
|
proc-macro = true
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
syn = { version = "1.0", features = [ "full", "visit" ] }
|
syn = { version = "1.0.7", features = [ "full", "visit" ] }
|
||||||
quote = "1.0"
|
quote = "1.0"
|
||||||
proc-macro2 = "1.0.4"
|
proc-macro2 = "1.0.6"
|
||||||
proc-macro-crate = "0.1.4"
|
proc-macro-crate = "0.1.4"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
|
|||||||
@@ -11,6 +11,6 @@ proc-macro = true
|
|||||||
srml-support-procedural-tools = { package = "srml-support-procedural-tools", path = "./tools" }
|
srml-support-procedural-tools = { package = "srml-support-procedural-tools", path = "./tools" }
|
||||||
sr-api-macros = { path = "../../../core/sr-api-macros" }
|
sr-api-macros = { path = "../../../core/sr-api-macros" }
|
||||||
|
|
||||||
proc-macro2 = "0.4.27"
|
proc-macro2 = "1.0.6"
|
||||||
quote = "0.6.12"
|
quote = "1.0.2"
|
||||||
syn = { version = "0.15.44", features = ["full"] }
|
syn = { version = "1.0.7", features = ["full"] }
|
||||||
|
|||||||
@@ -124,7 +124,7 @@ impl GenesisConfigDef {
|
|||||||
for line in &def.extra_genesis_config_lines {
|
for line in &def.extra_genesis_config_lines {
|
||||||
let doc = line.attrs.iter()
|
let doc = line.attrs.iter()
|
||||||
.filter_map(|a| a.parse_meta().ok())
|
.filter_map(|a| a.parse_meta().ok())
|
||||||
.filter(|m| m.name() == "doc")
|
.filter(|m| m.path().is_ident("doc"))
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let default = line.default.as_ref().map(|e| quote!( #e ))
|
let default = line.default.as_ref().map(|e| quote!( #e ))
|
||||||
|
|||||||
@@ -175,7 +175,7 @@ pub fn impl_metadata(scrate: &TokenStream, def: &DeclStorageDefExt) -> TokenStre
|
|||||||
let mut docs = TokenStream::new();
|
let mut docs = TokenStream::new();
|
||||||
for attr in line.attrs.iter().filter_map(|v| v.parse_meta().ok()) {
|
for attr in line.attrs.iter().filter_map(|v| v.parse_meta().ok()) {
|
||||||
if let syn::Meta::NameValue(meta) = attr {
|
if let syn::Meta::NameValue(meta) = attr {
|
||||||
if meta.ident == "doc" {
|
if meta.path.is_ident("doc") {
|
||||||
let lit = meta.lit;
|
let lit = meta.lit;
|
||||||
docs.extend(quote!(#lit,));
|
docs.extend(quote!(#lit,));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -307,7 +307,7 @@ impl StorageLineDefExt {
|
|||||||
|
|
||||||
let doc_attrs = storage_def.attrs.iter()
|
let doc_attrs = storage_def.attrs.iter()
|
||||||
.filter_map(|a| a.parse_meta().ok())
|
.filter_map(|a| a.parse_meta().ok())
|
||||||
.filter(|m| m.name() == "doc")
|
.filter(|m| m.path().is_ident("doc"))
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ edition = "2018"
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
srml-support-procedural-tools-derive = { package = "srml-support-procedural-tools-derive", path = "./derive" }
|
srml-support-procedural-tools-derive = { package = "srml-support-procedural-tools-derive", path = "./derive" }
|
||||||
proc-macro2 = "0.4.27"
|
proc-macro2 = "1.0.6"
|
||||||
quote = "0.6.12"
|
quote = "1.0.2"
|
||||||
syn = { version = "0.15.44", features = ["full"] }
|
syn = { version = "1.0.7", features = ["full"] }
|
||||||
proc-macro-crate = "0.1.4"
|
proc-macro-crate = "0.1.4"
|
||||||
|
|||||||
@@ -8,6 +8,6 @@ edition = "2018"
|
|||||||
proc-macro = true
|
proc-macro = true
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
proc-macro2 = "0.4.27"
|
proc-macro2 = "1.0.6"
|
||||||
quote = { version = "0.6.12", features = ["proc-macro"] }
|
quote = { version = "1.0.2", features = ["proc-macro"] }
|
||||||
syn = { version = "0.15.44", features = ["proc-macro" ,"full", "extra-traits", "parsing"] }
|
syn = { version = "1.0.7", features = ["proc-macro" ,"full", "extra-traits", "parsing"] }
|
||||||
|
|||||||
@@ -20,7 +20,7 @@
|
|||||||
|
|
||||||
use syn::{visit::{Visit, self}, parse::{Parse, ParseStream, Result}, Ident};
|
use syn::{visit::{Visit, self}, parse::{Parse, ParseStream, Result}, Ident};
|
||||||
use proc_macro2::{TokenStream, TokenTree};
|
use proc_macro2::{TokenStream, TokenTree};
|
||||||
use quote::{ToTokens, quote};
|
use quote::ToTokens;
|
||||||
use std::iter::once;
|
use std::iter::once;
|
||||||
use srml_support_procedural_tools_derive::{ToTokens, Parse};
|
use srml_support_procedural_tools_derive::{ToTokens, Parse};
|
||||||
|
|
||||||
@@ -124,13 +124,7 @@ impl Parse for Meta {
|
|||||||
impl ToTokens for Meta {
|
impl ToTokens for Meta {
|
||||||
fn to_tokens(&self, tokens: &mut TokenStream) {
|
fn to_tokens(&self, tokens: &mut TokenStream) {
|
||||||
match self.inner {
|
match self.inner {
|
||||||
syn::Meta::Word(ref ident) => {
|
syn::Meta::Path(ref path) => path.to_tokens(tokens),
|
||||||
let ident = ident.clone();
|
|
||||||
let toks = quote!{
|
|
||||||
#[#ident]
|
|
||||||
};
|
|
||||||
tokens.extend(toks);
|
|
||||||
},
|
|
||||||
syn::Meta::List(ref l) => l.to_tokens(tokens),
|
syn::Meta::List(ref l) => l.to_tokens(tokens),
|
||||||
syn::Meta::NameValue(ref n) => n.to_tokens(tokens),
|
syn::Meta::NameValue(ref n) => n.to_tokens(tokens),
|
||||||
}
|
}
|
||||||
@@ -187,10 +181,10 @@ impl<P: ToTokens> ToTokens for Opt<P> {
|
|||||||
pub fn extract_type_option(typ: &syn::Type) -> Option<syn::Type> {
|
pub fn extract_type_option(typ: &syn::Type) -> Option<syn::Type> {
|
||||||
if let syn::Type::Path(ref path) = typ {
|
if let syn::Type::Path(ref path) = typ {
|
||||||
let v = path.path.segments.last()?;
|
let v = path.path.segments.last()?;
|
||||||
if v.value().ident == "Option" {
|
if v.ident == "Option" {
|
||||||
// Option has only one type argument in angle bracket.
|
// Option has only one type argument in angle bracket.
|
||||||
if let syn::PathArguments::AngleBracketed(a) = &v.value().arguments {
|
if let syn::PathArguments::AngleBracketed(a) = &v.arguments {
|
||||||
if let syn::GenericArgument::Type(typ) = a.args.last()?.value() {
|
if let syn::GenericArgument::Type(typ) = a.args.last()? {
|
||||||
return Some(typ.clone())
|
return Some(typ.clone())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -230,7 +224,7 @@ impl<'ast> Visit<'ast> for ContainsIdent<'ast> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn visit_macro(&mut self, input: &'ast syn::Macro) {
|
fn visit_macro(&mut self, input: &'ast syn::Macro) {
|
||||||
self.visit_tokenstream(input.tts.clone());
|
self.visit_tokenstream(input.tokens.clone());
|
||||||
visit::visit_macro(self, input);
|
visit::visit_macro(self, input);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user