style: Migrate to stable-only rustfmt configuration

- Remove nightly-only features from .rustfmt.toml and vendor/ss58-registry/rustfmt.toml
- Removed features: imports_granularity, wrap_comments, comment_width,
  reorder_impl_items, spaces_around_ranges, binop_separator,
  match_arm_blocks, trailing_semicolon, trailing_comma
- Format all 898 affected files with stable rustfmt
- Ensures long-term reliability without nightly toolchain dependency
This commit is contained in:
2025-12-22 17:12:58 +03:00
parent 65b7f5e640
commit 4c8f281051
898 changed files with 8671 additions and 6432 deletions
@@ -414,11 +414,12 @@ fn parse_call_def(item_fn: &ItemFn) -> Result<(usize, BenchmarkCallDef)> {
Ok(match &call_defs[..] {
[(i, call_def)] => (*i, call_def.clone()), // = 1
[] => return missing_call(item_fn),
_ =>
_ => {
return Err(Error::new(
call_defs[1].1.attr_span(),
"Only one #[extrinsic_call] or #[block] attribute is allowed per benchmark.",
)),
))
},
})
}
@@ -432,7 +433,9 @@ impl BenchmarkDef {
let (verify_stmts, last_stmt) = match item_fn.sig.output {
ReturnType::Default =>
// no return type, last_stmt should be None
(Vec::from(&item_fn.block.stmts[(i + 1)..item_fn.block.stmts.len()]), None),
{
(Vec::from(&item_fn.block.stmts[(i + 1)..item_fn.block.stmts.len()]), None)
},
ReturnType::Type(_, _) => {
// defined return type, last_stmt should be Result<(), BenchmarkError>
// compatible and should not be included in verify_stmts
@@ -481,12 +484,13 @@ pub fn benchmarks(
let module: ItemMod = syn::parse(tokens)?;
let mod_span = module.span();
let where_clause = match syn::parse::<Nothing>(attrs.clone()) {
Ok(_) =>
Ok(_) => {
if instance {
quote!(T: Config<I>, I: 'static)
} else {
quote!(T: Config)
},
}
},
Err(_) => {
let mut where_clause_predicates = syn::parse::<WhereClause>(attrs)?.predicates;
@@ -1026,8 +1030,9 @@ fn expand_benchmark(
},
)
},
BenchmarkCallDef::Block { block, attr_span: _ } =>
(quote!(), quote!(#block), quote!(#block)),
BenchmarkCallDef::Block { block, attr_span: _ } => {
(quote!(), quote!(#block), quote!(#block))
},
};
let vis = benchmark_def.fn_vis;
@@ -96,22 +96,25 @@ impl Parse for RuntimeDeclaration {
let pallets_token = pallets.token;
match convert_pallets(pallets.content.inner.into_iter().collect())? {
PalletsConversion::Implicit(pallets) =>
Ok(RuntimeDeclaration::Implicit(ImplicitRuntimeDeclaration { pallets })),
PalletsConversion::Explicit(pallets) =>
PalletsConversion::Implicit(pallets) => {
Ok(RuntimeDeclaration::Implicit(ImplicitRuntimeDeclaration { pallets }))
},
PalletsConversion::Explicit(pallets) => {
Ok(RuntimeDeclaration::Explicit(ExplicitRuntimeDeclaration {
name,
where_section,
pallets,
pallets_token,
})),
PalletsConversion::ExplicitExpanded(pallets) =>
}))
},
PalletsConversion::ExplicitExpanded(pallets) => {
Ok(RuntimeDeclaration::ExplicitExpanded(ExplicitRuntimeDeclaration {
name,
where_section,
pallets,
pallets_token,
})),
}))
},
}
}
}
@@ -234,13 +237,13 @@ impl Parse for PalletDeclaration {
let res = Some(input.parse()?);
let _: Token![>] = input.parse()?;
res
} else if !(input.peek(Token![::]) && input.peek3(token::Brace)) &&
!input.peek(keyword::expanded) &&
!input.peek(keyword::exclude_parts) &&
!input.peek(keyword::use_parts) &&
!input.peek(Token![=]) &&
!input.peek(Token![,]) &&
!input.is_empty()
} else if !(input.peek(Token![::]) && input.peek3(token::Brace))
&& !input.peek(keyword::expanded)
&& !input.peek(keyword::exclude_parts)
&& !input.peek(keyword::use_parts)
&& !input.peek(Token![=])
&& !input.peek(Token![,])
&& !input.is_empty()
{
return Err(input.error(
"Unexpected tokens, expected one of `::$ident` `::{`, `exclude_parts`, `use_parts`, `=`, `,`",
@@ -264,11 +267,11 @@ impl Parse for PalletDeclaration {
let mut parts = parse_pallet_parts(input)?;
parts.extend(extra_parts.into_iter());
Some(parts)
} else if !input.peek(keyword::exclude_parts) &&
!input.peek(keyword::use_parts) &&
!input.peek(Token![=]) &&
!input.peek(Token![,]) &&
!input.is_empty()
} else if !input.peek(keyword::exclude_parts)
&& !input.peek(keyword::use_parts)
&& !input.peek(Token![=])
&& !input.peek(Token![,])
&& !input.is_empty()
{
return Err(input.error(
"Unexpected tokens, expected one of `::{`, `exclude_parts`, `use_parts`, `=`, `,`",
@@ -342,10 +345,10 @@ impl Parse for PalletPath {
PalletPath { inner: Path { leading_colon: None, segments: Punctuated::new() } };
let lookahead = input.lookahead1();
if lookahead.peek(Token![crate]) ||
lookahead.peek(Token![self]) ||
lookahead.peek(Token![super]) ||
lookahead.peek(Ident)
if lookahead.peek(Token![crate])
|| lookahead.peek(Token![self])
|| lookahead.peek(Token![super])
|| lookahead.peek(Ident)
{
let ident = input.call(Ident::parse_any)?;
res.inner.segments.push(ident.into());
@@ -720,7 +723,7 @@ fn convert_pallets(pallets: Vec<PalletDeclaration>) -> syn::Result<PalletsConver
// Check parts are correctly specified
match &pezpallet.specified_parts {
SpecifiedParts::Exclude(parts) | SpecifiedParts::Use(parts) =>
SpecifiedParts::Exclude(parts) | SpecifiedParts::Use(parts) => {
for part in parts {
if !available_parts.contains(part.keyword.name()) {
let msg = format!(
@@ -738,7 +741,8 @@ fn convert_pallets(pallets: Vec<PalletDeclaration>) -> syn::Result<PalletsConver
);
return Err(syn::Error::new(part.keyword.span(), msg));
}
},
}
},
SpecifiedParts::All => (),
}
@@ -78,7 +78,9 @@ impl syn::parse::Parse for DeriveImplAttrArgs {
(default_impl_path, Some(args.clone()))
},
Some(PathSegment { arguments: PathArguments::None, .. }) => (default_impl_path, None),
_ => return Err(syn::Error::new(default_impl_path.span(), "Invalid default impl path")),
_ => {
return Err(syn::Error::new(default_impl_path.span(), "Invalid default impl path"))
},
};
let lookahead = input.lookahead1();
@@ -228,13 +230,14 @@ fn compute_disambiguation_path(
) -> Result<Path> {
match (disambiguation_path, foreign_impl.clone().trait_) {
(Some(disambiguation_path), _) => Ok(disambiguation_path),
(None, Some((_, foreign_impl_path, _))) =>
(None, Some((_, foreign_impl_path, _))) => {
if default_impl_path.segments.len() > 1 {
let scope = default_impl_path.segments.first();
Ok(parse_quote!(#scope :: #foreign_impl_path))
} else {
Ok(foreign_impl_path)
},
}
},
_ => Err(syn::Error::new(
default_impl_path.span(),
"Impl statement must have a defined type being implemented \
@@ -820,15 +820,15 @@ pub fn register_default_impl(attrs: TokenStream, tokens: TokenStream) -> TokenSt
pub fn inject_runtime_type(_: TokenStream, tokens: TokenStream) -> TokenStream {
let item = tokens.clone();
let item = syn::parse_macro_input!(item as TraitItemType);
if item.ident != "RuntimeCall" &&
item.ident != "RuntimeEvent" &&
item.ident != "RuntimeTask" &&
item.ident != "RuntimeViewFunction" &&
item.ident != "RuntimeOrigin" &&
item.ident != "RuntimeHoldReason" &&
item.ident != "RuntimeFreezeReason" &&
item.ident != "RuntimeParameters" &&
item.ident != "PalletInfo"
if item.ident != "RuntimeCall"
&& item.ident != "RuntimeEvent"
&& item.ident != "RuntimeTask"
&& item.ident != "RuntimeViewFunction"
&& item.ident != "RuntimeOrigin"
&& item.ident != "RuntimeHoldReason"
&& item.ident != "RuntimeFreezeReason"
&& item.ident != "RuntimeParameters"
&& item.ident != "PalletInfo"
{
return syn::Error::new_spanned(
item,
@@ -138,13 +138,14 @@ pub fn derive_default_no_bound(input: proc_macro::TokenStream) -> proc_macro::To
},
}
},
Data::Union(union_) =>
Data::Union(union_) => {
return syn::Error::new_spanned(
union_.union_token,
"Union type not supported by `derive(DefaultNoBound)`",
)
.to_compile_error()
.into(),
.into()
},
};
quote!(
@@ -27,9 +27,9 @@ pub fn derive_partial_ord_no_bound(input: proc_macro::TokenStream) -> proc_macro
let name = &input.ident;
let (impl_generics, ty_generics, where_clause) = input.generics.split_for_impl();
let impl_ = match input.data {
syn::Data::Struct(struct_) =>
match struct_.fields {
let impl_ =
match input.data {
syn::Data::Struct(struct_) => match struct_.fields {
syn::Fields::Named(named) => {
let fields =
named.named.iter().map(|i| &i.ident).map(
@@ -66,15 +66,15 @@ pub fn derive_partial_ord_no_bound(input: proc_macro::TokenStream) -> proc_macro
quote::quote!(Some(core::cmp::Ordering::Equal))
},
},
syn::Data::Enum(_) => {
let msg = "Enum type not supported by `derive(PartialOrdNoBound)`";
return syn::Error::new(input.span(), msg).to_compile_error().into();
},
syn::Data::Union(_) => {
let msg = "Union type not supported by `derive(PartialOrdNoBound)`";
return syn::Error::new(input.span(), msg).to_compile_error().into();
},
};
syn::Data::Enum(_) => {
let msg = "Enum type not supported by `derive(PartialOrdNoBound)`";
return syn::Error::new(input.span(), msg).to_compile_error().into();
},
syn::Data::Union(_) => {
let msg = "Union type not supported by `derive(PartialOrdNoBound)`";
return syn::Error::new(input.span(), msg).to_compile_error().into();
},
};
quote::quote!(
const _: () = {
@@ -50,10 +50,12 @@ fn parse_doc_value(attr: &Attribute) -> syn::Result<Option<DocMetaValue>> {
match &meta.value {
syn::Expr::Lit(lit) => Ok(Some(DocMetaValue::Lit(lit.lit.clone()))),
syn::Expr::Macro(mac) if mac.mac.path.is_ident("include_str") =>
Ok(Some(DocMetaValue::Path(mac.mac.parse_body()?))),
_ =>
Err(syn::Error::new(attr.span(), "Expected `= \"docs\"` or `= include_str!(\"PATH\")`")),
syn::Expr::Macro(mac) if mac.mac.path.is_ident("include_str") => {
Ok(Some(DocMetaValue::Path(mac.mac.parse_body()?)))
},
_ => {
Err(syn::Error::new(attr.span(), "Expected `= \"docs\"` or `= include_str!(\"PATH\")`"))
},
}
}
@@ -83,9 +83,9 @@ pub fn expand_genesis_config(def: &mut Def) -> proc_macro2::TokenStream {
let serde_crate = format!("{}::__private::serde", pezframe_support.to_token_stream());
match genesis_config_item {
syn::Item::Enum(syn::ItemEnum { attrs, .. }) |
syn::Item::Struct(syn::ItemStruct { attrs, .. }) |
syn::Item::Type(syn::ItemType { attrs, .. }) => {
syn::Item::Enum(syn::ItemEnum { attrs, .. })
| syn::Item::Struct(syn::ItemStruct { attrs, .. })
| syn::Item::Type(syn::ItemType { attrs, .. }) => {
if get_doc_literals(attrs).is_empty() {
attrs.push(syn::parse_quote!(
#[doc = r"
@@ -198,8 +198,8 @@ pub fn process_generics(def: &mut Def) -> syn::Result<Vec<ResultOnEmptyStructMet
let on_empty = on_empty.unwrap_or_else(|| default_on_empty(value));
args.args.push(syn::GenericArgument::Type(on_empty));
},
StorageGenerics::Map { hasher, key, value, query_kind, on_empty, max_values } |
StorageGenerics::CountedMap {
StorageGenerics::Map { hasher, key, value, query_kind, on_empty, max_values }
| StorageGenerics::CountedMap {
hasher,
key,
value,
@@ -241,8 +241,8 @@ pub fn process_generics(def: &mut Def) -> syn::Result<Vec<ResultOnEmptyStructMet
let max_values = max_values.unwrap_or_else(|| default_max_values.clone());
args.args.push(syn::GenericArgument::Type(max_values));
},
StorageGenerics::NMap { keygen, value, query_kind, on_empty, max_values } |
StorageGenerics::CountedNMap {
StorageGenerics::NMap { keygen, value, query_kind, on_empty, max_values }
| StorageGenerics::CountedNMap {
keygen,
value,
query_kind,
@@ -295,8 +295,8 @@ pub fn process_generics(def: &mut Def) -> syn::Result<Vec<ResultOnEmptyStructMet
// Here, we only need to check if OnEmpty is *not* specified, and if so, then we have to
// generate a default OnEmpty struct for it.
if on_empty_idx >= args.args.len() &&
matches!(storage_def.query_kind.as_ref(), Some(QueryKind::ResultQuery(_, _)))
if on_empty_idx >= args.args.len()
&& matches!(storage_def.query_kind.as_ref(), Some(QueryKind::ResultQuery(_, _)))
{
let value_ty = match args.args[value_idx].clone() {
syn::GenericArgument::Type(ty) => ty,
@@ -21,8 +21,9 @@ use syn::spanned::Spanned;
pub fn expand_view_functions(def: &Def) -> TokenStream {
let (span, where_clause, view_fns) = match def.view_functions.as_ref() {
Some(view_fns) =>
(view_fns.attr_span, view_fns.where_clause.clone(), view_fns.view_functions.clone()),
Some(view_fns) => {
(view_fns.attr_span, view_fns.where_clause.clone(), view_fns.view_functions.clone())
},
None => (def.item.span(), def.config.where_clause.clone(), Vec::new()),
};
@@ -259,7 +259,10 @@ impl CallDef {
let item_impl = if let syn::Item::Impl(item) = item {
item
} else {
return Err(syn::Error::new(item.span(), "Invalid pezpallet::call, expected item impl"));
return Err(syn::Error::new(
item.span(),
"Invalid pezpallet::call, expected item impl",
));
};
crate::deprecation::prevent_deprecation_attr_on_outer_enum(&item_impl.attrs)?;
@@ -406,11 +409,12 @@ impl CallDef {
let final_index = match call_index {
Some(i) => i,
None =>
None => {
last_index.map_or(Some(0), |idx| idx.checked_add(1)).ok_or_else(|| {
let msg = "Call index doesn't fit into u8, index is 256";
syn::Error::new(method.sig.span(), msg)
})?,
})?
},
};
last_index = Some(final_index);
@@ -112,11 +112,12 @@ impl CompositeDef {
// a fixed variant count.
for variant in &item.variants {
match variant.fields {
syn::Fields::Named(_) | syn::Fields::Unnamed(_) =>
syn::Fields::Named(_) | syn::Fields::Unnamed(_) => {
return Err(syn::Error::new(
variant.ident.span(),
"The composite enum does not support variants with fields!",
)),
))
},
syn::Fields::Unit => (),
}
}
@@ -309,16 +309,22 @@ fn has_expected_system_config(path: syn::Path, pezframe_system: &syn::Path) -> b
(true, false) =>
// We can't use the path to `pezframe_system` from `frame` if `pezframe_system` is not
// being in scope through `frame`.
return false,
{
return false
},
(false, true) =>
// We know that the only valid pezframe_system path is one that is `pezframe_system`, as
// `frame` re-exports it as such.
{
syn::parse2::<syn::Path>(quote::quote!(pezframe_system))
.expect("is a valid path; qed"),
.expect("is a valid path; qed")
},
(_, _) =>
// They are either both `pezframe_system` or both
// `pezkuwi_sdk_frame::xyz::pezframe_system`.
pezframe_system.clone(),
{
pezframe_system.clone()
},
};
expected_system_config
@@ -331,8 +337,8 @@ fn has_expected_system_config(path: syn::Path, pezframe_system: &syn::Path) -> b
.segments
.into_iter()
.map(|ps| ps.ident)
.collect::<Vec<_>>() ==
path.segments.into_iter().map(|ps| ps.ident).collect::<Vec<_>>()
.collect::<Vec<_>>()
== path.segments.into_iter().map(|ps| ps.ident).collect::<Vec<_>>()
}
/// Replace ident `Self` by `T`
@@ -340,10 +346,12 @@ pub fn replace_self_by_t(input: proc_macro2::TokenStream) -> proc_macro2::TokenS
input
.into_iter()
.map(|token_tree| match token_tree {
proc_macro2::TokenTree::Group(group) =>
proc_macro2::Group::new(group.delimiter(), replace_self_by_t(group.stream())).into(),
proc_macro2::TokenTree::Ident(ident) if ident == "Self" =>
proc_macro2::Ident::new("T", ident.span()).into(),
proc_macro2::TokenTree::Group(group) => {
proc_macro2::Group::new(group.delimiter(), replace_self_by_t(group.stream())).into()
},
proc_macro2::TokenTree::Ident(ident) if ident == "Self" => {
proc_macro2::Ident::new("T", ident.span()).into()
},
other => other,
})
.collect()
@@ -101,8 +101,8 @@ impl ErrorDef {
};
match &variant.discriminant {
None |
Some((_, syn::Expr::Lit(syn::ExprLit { lit: syn::Lit::Int(_), .. }))) => {},
None
| Some((_, syn::Expr::Lit(syn::ExprLit { lit: syn::Lit::Int(_), .. }))) => {},
Some((_, expr)) => {
let msg = "Invalid pezpallet::error, only integer discriminants are supported";
return Err(syn::Error::new(expr.span(), msg));
@@ -285,12 +285,13 @@ impl Def {
// ensure that if `task_enum` is specified, `tasks` is also specified
match (&task_enum, &tasks) {
(Some(_), None) =>
(Some(_), None) => {
return Err(syn::Error::new(
*item_span,
"Missing `#[pezpallet::tasks_experimental]` impl",
)),
(None, Some(tasks)) =>
))
},
(None, Some(tasks)) => {
if tasks.tasks_attr.is_none() {
return Err(syn::Error::new(
tasks.item_impl.impl_token.span(),
@@ -298,7 +299,8 @@ impl Def {
task enum has been omitted",
));
} else {
},
}
},
_ => (),
}
@@ -52,10 +52,10 @@ pub enum PalletStorageAttr {
impl PalletStorageAttr {
fn attr_span(&self) -> proc_macro2::Span {
match self {
Self::Getter(_, span) |
Self::StorageName(_, span) |
Self::Unbounded(span) |
Self::WhitelistStorage(span) => *span,
Self::Getter(_, span)
| Self::StorageName(_, span)
| Self::Unbounded(span)
| Self::WhitelistStorage(span) => *span,
Self::DisableTryDecodeStorage(span) => *span,
}
}
@@ -124,17 +124,20 @@ impl PalletStorageAttrInfo {
for attr in attrs {
match attr {
PalletStorageAttr::Getter(ident, ..) if getter.is_none() => getter = Some(ident),
PalletStorageAttr::StorageName(name, ..) if rename_as.is_none() =>
rename_as = Some(name),
PalletStorageAttr::StorageName(name, ..) if rename_as.is_none() => {
rename_as = Some(name)
},
PalletStorageAttr::Unbounded(..) if !unbounded => unbounded = true,
PalletStorageAttr::WhitelistStorage(..) if !whitelisted => whitelisted = true,
PalletStorageAttr::DisableTryDecodeStorage(..) if !disable_try_decode_storage =>
disable_try_decode_storage = true,
attr =>
PalletStorageAttr::DisableTryDecodeStorage(..) if !disable_try_decode_storage => {
disable_try_decode_storage = true
},
attr => {
return Err(syn::Error::new(
attr.attr_span(),
"Invalid attribute: Duplicate attribute",
)),
))
},
}
}
@@ -269,10 +272,12 @@ impl StorageGenerics {
Self::Map { value, key, .. } => Metadata::Map { value, key },
Self::CountedMap { value, key, .. } => Metadata::CountedMap { value, key },
Self::Value { value, .. } => Metadata::Value { value },
Self::NMap { keygen, value, .. } =>
Metadata::NMap { keys: collect_keys(&keygen)?, keygen, value },
Self::CountedNMap { keygen, value, .. } =>
Metadata::CountedNMap { keys: collect_keys(&keygen)?, keygen, value },
Self::NMap { keygen, value, .. } => {
Metadata::NMap { keys: collect_keys(&keygen)?, keygen, value }
},
Self::CountedNMap { keygen, value, .. } => {
Metadata::CountedNMap { keys: collect_keys(&keygen)?, keygen, value }
},
};
Ok(res)
@@ -281,12 +286,12 @@ impl StorageGenerics {
/// Return the query kind from the defined generics
fn query_kind(&self) -> Option<syn::Type> {
match &self {
Self::DoubleMap { query_kind, .. } |
Self::Map { query_kind, .. } |
Self::CountedMap { query_kind, .. } |
Self::Value { query_kind, .. } |
Self::NMap { query_kind, .. } |
Self::CountedNMap { query_kind, .. } => query_kind.clone(),
Self::DoubleMap { query_kind, .. }
| Self::Map { query_kind, .. }
| Self::CountedMap { query_kind, .. }
| Self::Value { query_kind, .. }
| Self::NMap { query_kind, .. }
| Self::CountedNMap { query_kind, .. } => query_kind.clone(),
}
}
}
@@ -328,8 +333,8 @@ fn check_generics(
};
for (gen_name, gen_binding) in map {
if !mandatory_generics.contains(&gen_name.as_str()) &&
!optional_generics.contains(&gen_name.as_str())
if !mandatory_generics.contains(&gen_name.as_str())
&& !optional_generics.contains(&gen_name.as_str())
{
let msg = format!(
"Invalid pezpallet::storage, Unexpected generic `{}` for `{}`. {}",
@@ -600,8 +605,9 @@ fn process_unnamed_generics(
};
let res = match storage {
StorageKind::Value =>
(None, Metadata::Value { value: retrieve_arg(1)? }, retrieve_arg(2).ok(), false),
StorageKind::Value => {
(None, Metadata::Value { value: retrieve_arg(1)? }, retrieve_arg(2).ok(), false)
},
StorageKind::Map => (
None,
Metadata::Map { key: retrieve_arg(2)?, value: retrieve_arg(3)? },
@@ -841,16 +847,22 @@ impl StorageDef {
.segments
.last()
.map_or(false, |s| s.ident == "OptionQuery") =>
return Ok(Some(QueryKind::OptionQuery)),
{
return Ok(Some(QueryKind::OptionQuery))
},
Type::Path(TypePath { path: Path { segments, .. }, .. })
if segments.last().map_or(false, |s| s.ident == "ResultQuery") =>
{
segments
.last()
.expect("segments is checked to have the last value; qed")
.clone(),
.clone()
},
Type::Path(path)
if path.path.segments.last().map_or(false, |s| s.ident == "ValueQuery") =>
return Ok(Some(QueryKind::ValueQuery)),
{
return Ok(Some(QueryKind::ValueQuery))
},
_ => return Ok(None),
};
@@ -415,11 +415,12 @@ impl TryFrom<PalletTaskAttr<TaskAttrMeta>> for TaskIndexAttr {
let colons = value.colons;
match value.meta {
TaskAttrMeta::TaskIndex(meta) => parse2(quote!(#pound[#pezpallet #colons #meta])),
_ =>
_ => {
return Err(Error::new(
value.span(),
format!("`{:?}` cannot be converted to a `TaskIndexAttr`", value.meta),
)),
))
},
}
}
}
@@ -433,11 +434,12 @@ impl TryFrom<PalletTaskAttr<TaskAttrMeta>> for TaskConditionAttr {
let colons = value.colons;
match value.meta {
TaskAttrMeta::TaskCondition(meta) => parse2(quote!(#pound[#pezpallet #colons #meta])),
_ =>
_ => {
return Err(Error::new(
value.span(),
format!("`{:?}` cannot be converted to a `TaskConditionAttr`", value.meta),
)),
))
},
}
}
}
@@ -451,11 +453,12 @@ impl TryFrom<PalletTaskAttr<TaskAttrMeta>> for TaskWeightAttr {
let colons = value.colons;
match value.meta {
TaskAttrMeta::TaskWeight(meta) => parse2(quote!(#pound[#pezpallet #colons #meta])),
_ =>
_ => {
return Err(Error::new(
value.span(),
format!("`{:?}` cannot be converted to a `TaskWeightAttr`", value.meta),
)),
))
},
}
}
}
@@ -469,11 +472,12 @@ impl TryFrom<PalletTaskAttr<TaskAttrMeta>> for TaskListAttr {
let colons = value.colons;
match value.meta {
TaskAttrMeta::TaskList(meta) => parse2(quote!(#pound[#pezpallet #colons #meta])),
_ =>
_ => {
return Err(Error::new(
value.span(),
format!("`{:?}` cannot be converted to a `TaskListAttr`", value.meta),
)),
))
},
}
}
}
@@ -534,12 +538,12 @@ fn partition_task_attrs(item: &ImplItemFn) -> (Vec<syn::Attribute>, Vec<syn::Att
};
// N.B: the `PartialEq` impl between `Ident` and `&str` is more efficient than
// parsing and makes no stack or heap allocations
prefix.ident == "pezpallet" &&
(suffix.ident == "tasks_experimental" ||
suffix.ident == "task_list" ||
suffix.ident == "task_condition" ||
suffix.ident == "task_weight" ||
suffix.ident == "task_index")
prefix.ident == "pezpallet"
&& (suffix.ident == "tasks_experimental"
|| suffix.ident == "task_list"
|| suffix.ident == "task_condition"
|| suffix.ident == "task_weight"
|| suffix.ident == "task_index")
})
}
@@ -34,8 +34,8 @@ pub fn derive_pallet_error(input: proc_macro::TokenStream) -> proc_macro::TokenS
let max_encoded_size = match data {
syn::Data::Struct(syn::DataStruct { fields, .. }) => match fields {
syn::Fields::Named(syn::FieldsNamed { named: fields, .. }) |
syn::Fields::Unnamed(syn::FieldsUnnamed { unnamed: fields, .. }) => {
syn::Fields::Named(syn::FieldsNamed { named: fields, .. })
| syn::Fields::Unnamed(syn::FieldsUnnamed { unnamed: fields, .. }) => {
let maybe_field_tys = fields
.iter()
.map(|f| generate_field_types(f, &pezframe_support))
@@ -166,8 +166,8 @@ fn generate_variant_field_types(
}
match &variant.fields {
syn::Fields::Named(syn::FieldsNamed { named: fields, .. }) |
syn::Fields::Unnamed(syn::FieldsUnnamed { unnamed: fields, .. }) => {
syn::Fields::Named(syn::FieldsNamed { named: fields, .. })
| syn::Fields::Unnamed(syn::FieldsUnnamed { unnamed: fields, .. }) => {
let field_tys = fields
.iter()
.map(|field| generate_field_types(field, scrate))
@@ -102,8 +102,9 @@ fn construct_runtime_implicit_to_explicit(
let runtime_param = &pezpallet.runtime_param;
let pezpallet_segment_and_instance =
match (&pezpallet.pezpallet_segment, &pezpallet.instance) {
(Some(segment), Some(instance)) =>
quote::quote!(::#segment<#runtime_param, #instance>),
(Some(segment), Some(instance)) => {
quote::quote!(::#segment<#runtime_param, #instance>)
},
(Some(segment), None) => quote::quote!(::#segment<#runtime_param>),
(None, Some(instance)) => quote::quote!(<#instance>),
(None, None) => quote::quote!(),
@@ -228,8 +228,8 @@ impl StorageType {
>;
}
},
Self::CountedMap { value_ty, query_type, hasher_ty, key_ty, .. } |
Self::Map { value_ty, query_type, hasher_ty, key_ty, .. } => {
Self::CountedMap { value_ty, query_type, hasher_ty, key_ty, .. }
| Self::Map { value_ty, query_type, hasher_ty, key_ty, .. } => {
let query_type = query_type.as_ref().map(|(c, t)| quote!(#c #t));
let map_type = Ident::new(
match self {
@@ -294,11 +294,11 @@ impl StorageType {
/// The prefix for this storage type.
fn prefix(&self) -> &Type {
match self {
Self::Value { prefix, .. } |
Self::Map { prefix, .. } |
Self::CountedMap { prefix, .. } |
Self::NMap { prefix, .. } |
Self::DoubleMap { prefix, .. } => prefix,
Self::Value { prefix, .. }
| Self::Map { prefix, .. }
| Self::CountedMap { prefix, .. }
| Self::NMap { prefix, .. }
| Self::DoubleMap { prefix, .. } => prefix,
}
}
}
@@ -550,7 +550,7 @@ fn generate_storage_instance(
.unwrap_or_default();
let (pezpallet_prefix, impl_generics, type_generics) = match prefix_type {
PrefixType::Compatibility =>
PrefixType::Compatibility => {
if !impl_generics_used_by_prefix.is_empty() {
let type_generics = impl_generics_used_by_prefix.iter().map(|g| &g.ident);
let impl_generics = impl_generics_used_by_prefix.iter();
@@ -571,15 +571,17 @@ fn generate_storage_instance(
prefix,
"If there are no generics, the prefix is only allowed to be an identifier.",
));
},
}
},
PrefixType::Verbatim => {
let prefix_str = match prefix.get_ident() {
Some(p) => p.to_string(),
None =>
None => {
return Err(Error::new_spanned(
prefix,
"Prefix type `verbatim` requires that the prefix is an ident.",
)),
))
},
};
(quote!(#prefix_str), quote!(), quote!())