Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes warnings in frame-support-procedural crate #4915

Merged
merged 5 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ pub enum RuntimeDeclaration {
/// Declaration of a runtime with some pallet with implicit declaration of parts.
#[derive(Debug)]
pub struct ImplicitRuntimeDeclaration {
pub name: Ident,
pub where_section: Option<WhereSection>,
pub pallets: Vec<PalletDeclaration>,
}

Expand Down Expand Up @@ -98,11 +96,7 @@ impl Parse for RuntimeDeclaration {

match convert_pallets(pallets.content.inner.into_iter().collect())? {
PalletsConversion::Implicit(pallets) =>
Ok(RuntimeDeclaration::Implicit(ImplicitRuntimeDeclaration {
name,
where_section,
pallets,
})),
Ok(RuntimeDeclaration::Implicit(ImplicitRuntimeDeclaration { pallets })),
PalletsConversion::Explicit(pallets) =>
Ok(RuntimeDeclaration::Explicit(ExplicitRuntimeDeclaration {
name,
Expand All @@ -124,9 +118,6 @@ impl Parse for RuntimeDeclaration {
#[derive(Debug)]
pub struct WhereSection {
pub span: Span,
pub block: syn::TypePath,
pub node_block: syn::TypePath,
pub unchecked_extrinsic: syn::TypePath,
}

impl Parse for WhereSection {
Expand All @@ -145,18 +136,17 @@ impl Parse for WhereSection {
}
input.parse::<Token![,]>()?;
}
let block = remove_kind(input, WhereKind::Block, &mut definitions)?.value;
let node_block = remove_kind(input, WhereKind::NodeBlock, &mut definitions)?.value;
let unchecked_extrinsic =
remove_kind(input, WhereKind::UncheckedExtrinsic, &mut definitions)?.value;
remove_kind(input, WhereKind::Block, &mut definitions)?;
remove_kind(input, WhereKind::NodeBlock, &mut definitions)?;
remove_kind(input, WhereKind::UncheckedExtrinsic, &mut definitions)?;
if let Some(WhereDefinition { ref kind_span, ref kind, .. }) = definitions.first() {
let msg = format!(
"`{:?}` was declared above. Please use exactly one declaration for `{:?}`.",
kind, kind
);
return Err(Error::new(*kind_span, msg))
}
Ok(Self { span: input.span(), block, node_block, unchecked_extrinsic })
Ok(Self { span: input.span() })
}
}

Expand All @@ -171,7 +161,6 @@ pub enum WhereKind {
pub struct WhereDefinition {
pub kind_span: Span,
pub kind: WhereKind,
pub value: syn::TypePath,
}

impl Parse for WhereDefinition {
Expand All @@ -187,14 +176,10 @@ impl Parse for WhereDefinition {
return Err(lookahead.error())
};

Ok(Self {
kind_span,
kind,
value: {
let _: Token![=] = input.parse()?;
input.parse()?
},
})
let _: Token![=] = input.parse()?;
let _: syn::TypePath = input.parse()?;

Ok(Self { kind_span, kind })
}
}

Expand Down
36 changes: 19 additions & 17 deletions substrate/frame/support/procedural/src/pallet/expand/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,23 +71,25 @@ pub fn expand_error(def: &mut Def) -> proc_macro2::TokenStream {
)
);

let as_str_matches = error.variants.iter().map(
|VariantDef { ident: variant, field: field_ty, docs: _, cfg_attrs }| {
let variant_str = variant.to_string();
let cfg_attrs = cfg_attrs.iter().map(|attr| attr.to_token_stream());
match field_ty {
Some(VariantField { is_named: true }) => {
quote::quote_spanned!(error.attr_span => #( #cfg_attrs )* Self::#variant { .. } => #variant_str,)
},
Some(VariantField { is_named: false }) => {
quote::quote_spanned!(error.attr_span => #( #cfg_attrs )* Self::#variant(..) => #variant_str,)
},
None => {
quote::quote_spanned!(error.attr_span => #( #cfg_attrs )* Self::#variant => #variant_str,)
},
}
},
);
let as_str_matches =
error
.variants
.iter()
.map(|VariantDef { ident: variant, field: field_ty, cfg_attrs }| {
let variant_str = variant.to_string();
let cfg_attrs = cfg_attrs.iter().map(|attr| attr.to_token_stream());
match field_ty {
Some(VariantField { is_named: true }) => {
quote::quote_spanned!(error.attr_span => #( #cfg_attrs )* Self::#variant { .. } => #variant_str,)
},
Some(VariantField { is_named: false }) => {
quote::quote_spanned!(error.attr_span => #( #cfg_attrs )* Self::#variant(..) => #variant_str,)
},
None => {
quote::quote_spanned!(error.attr_span => #( #cfg_attrs )* Self::#variant => #variant_str,)
},
}
});

let error_item = {
let item = &mut def.item.content.as_mut().expect("Checked by def parser").1[error.index];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,6 @@ pub mod keyword {
}

pub struct CompositeDef {
/// The index of the CompositeDef item in the pallet module.
pub index: usize,
/// The composite keyword used (contains span).
pub composite_keyword: keyword::CompositeKeyword,
/// Name of the associated type.
Expand All @@ -104,7 +102,7 @@ pub struct CompositeDef {
impl CompositeDef {
pub fn try_from(
attr_span: proc_macro2::Span,
index: usize,
_index: usize,
scrate: &syn::Path,
item: &mut syn::Item,
) -> syn::Result<Self> {
Expand Down Expand Up @@ -180,7 +178,6 @@ impl CompositeDef {
syn::parse2::<keyword::CompositeKeyword>(item.ident.to_token_stream())?;

Ok(CompositeDef {
index,
composite_keyword,
attr_span,
generics: item.generics.clone(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ pub struct ConfigDef {
pub has_event_type: bool,
/// The where clause on trait definition but modified so `Self` is `T`.
pub where_clause: Option<syn::WhereClause>,
/// The span of the pallet::config attribute.
pub attr_span: proc_macro2::Span,
/// Whether a default sub-trait should be generated.
///
/// Contains default sub-trait items (instantiated by `#[pallet::config(with_default)]`).
Expand Down Expand Up @@ -325,7 +323,7 @@ pub fn replace_self_by_t(input: proc_macro2::TokenStream) -> proc_macro2::TokenS
impl ConfigDef {
pub fn try_from(
frame_system: &syn::Path,
attr_span: proc_macro2::Span,
_attr_span: proc_macro2::Span,
index: usize,
item: &mut syn::Item,
enable_default: bool,
Expand Down Expand Up @@ -484,7 +482,6 @@ impl ConfigDef {
consts_metadata,
has_event_type,
where_clause,
attr_span,
default_sub_trait,
})
}
Expand Down
10 changes: 1 addition & 9 deletions substrate/frame/support/procedural/src/pallet/parse/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
// limitations under the License.

use super::helper;
use frame_support_procedural_tools::get_doc_literals;
use quote::ToTokens;
use syn::{spanned::Spanned, Fields};

Expand All @@ -37,8 +36,6 @@ pub struct VariantDef {
pub ident: syn::Ident,
/// The variant field, if any.
pub field: Option<VariantField>,
/// The variant doc literals.
pub docs: Vec<syn::Expr>,
/// The `cfg` attributes.
pub cfg_attrs: Vec<syn::Attribute>,
}
Expand Down Expand Up @@ -101,12 +98,7 @@ impl ErrorDef {
}
let cfg_attrs: Vec<syn::Attribute> = helper::get_item_cfg_attrs(&variant.attrs);

Ok(VariantDef {
ident: variant.ident.clone(),
field: field_ty,
docs: get_doc_literals(&variant.attrs),
cfg_attrs,
})
Ok(VariantDef { ident: variant.ident.clone(), field: field_ty, cfg_attrs })
})
.collect::<Result<_, _>>()?;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ pub struct ExtraConstantsDef {
pub where_clause: Option<syn::WhereClause>,
/// A set of usage of instance, must be check for consistency with trait.
pub instances: Vec<helper::InstanceUsage>,
/// The index of call item in pallet module.
pub index: usize,
/// The extra constant defined.
pub extra_constants: Vec<ExtraConstantDef>,
}
Expand Down Expand Up @@ -77,7 +75,7 @@ impl syn::parse::Parse for ExtraConstAttr {
}

impl ExtraConstantsDef {
pub fn try_from(index: usize, item: &mut syn::Item) -> syn::Result<Self> {
pub fn try_from(_index: usize, item: &mut syn::Item) -> syn::Result<Self> {
let item = if let syn::Item::Impl(item) = item {
item
} else {
Expand Down Expand Up @@ -150,11 +148,6 @@ impl ExtraConstantsDef {
});
}

Ok(Self {
index,
instances,
where_clause: item.generics.where_clause.clone(),
extra_constants,
})
Ok(Self { instances, where_clause: item.generics.where_clause.clone(), extra_constants })
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ use syn::spanned::Spanned;

/// Definition for pallet genesis build implementation.
pub struct GenesisBuildDef {
/// The index of item in pallet module.
pub index: usize,
/// A set of usage of instance, must be check for consistency with trait.
pub instances: Option<Vec<helper::InstanceUsage>>,
/// The where_clause used.
Expand All @@ -33,7 +31,7 @@ pub struct GenesisBuildDef {
impl GenesisBuildDef {
pub fn try_from(
attr_span: proc_macro2::Span,
index: usize,
_index: usize,
item: &mut syn::Item,
) -> syn::Result<Self> {
let item = if let syn::Item::Impl(item) = item {
Expand All @@ -56,6 +54,6 @@ impl GenesisBuildDef {
let instances =
helper::check_genesis_builder_usage(item_trait)?.map(|instances| vec![instances]);

Ok(Self { attr_span, index, instances, where_clause: item.generics.where_clause.clone() })
Ok(Self { attr_span, instances, where_clause: item.generics.where_clause.clone() })
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ use syn::spanned::Spanned;

/// Implementation of the pallet hooks.
pub struct HooksDef {
/// The index of item in pallet.
pub index: usize,
/// A set of usage of instance, must be check for consistency with trait.
pub instances: Vec<helper::InstanceUsage>,
/// The where_clause used.
Expand All @@ -35,7 +33,7 @@ pub struct HooksDef {
impl HooksDef {
pub fn try_from(
attr_span: proc_macro2::Span,
index: usize,
_index: usize,
item: &mut syn::Item,
) -> syn::Result<Self> {
let item = if let syn::Item::Impl(item) = item {
Expand Down Expand Up @@ -77,7 +75,6 @@ impl HooksDef {

Ok(Self {
attr_span,
index,
instances,
has_runtime_upgrade,
where_clause: item.generics.where_clause.clone(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,12 @@ use syn::spanned::Spanned;

/// The definition of the pallet inherent implementation.
pub struct InherentDef {
/// The index of inherent item in pallet module.
pub index: usize,
/// A set of usage of instance, must be check for consistency with trait.
pub instances: Vec<helper::InstanceUsage>,
}

impl InherentDef {
pub fn try_from(index: usize, item: &mut syn::Item) -> syn::Result<Self> {
pub fn try_from(_index: usize, item: &mut syn::Item) -> syn::Result<Self> {
let item = if let syn::Item::Impl(item) = item {
item
} else {
Expand Down Expand Up @@ -55,6 +53,6 @@ impl InherentDef {
helper::check_impl_gen(&item.generics, item.impl_token.span())?,
];

Ok(InherentDef { index, instances })
Ok(InherentDef { instances })
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,6 @@ impl syn::parse::Parse for PalletAttr {
#[derive(Clone)]
pub struct InheritedCallWeightAttr {
pub typename: syn::Type,
pub span: proc_macro2::Span,
}

impl syn::parse::Parse for InheritedCallWeightAttr {
Expand All @@ -744,6 +743,6 @@ impl syn::parse::Parse for InheritedCallWeightAttr {
return Err(lookahead.error())
};

Ok(Self { typename: buffer.parse()?, span: input.span() })
Ok(Self { typename: buffer.parse()? })
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,13 @@ use syn::spanned::Spanned;
/// * `struct Origin`
/// * `enum Origin`
pub struct OriginDef {
/// The index of item in pallet module.
pub index: usize,
pub has_instance: bool,
pub is_generic: bool,
/// A set of usage of instance, must be check for consistency with trait.
pub instances: Vec<helper::InstanceUsage>,
}

impl OriginDef {
pub fn try_from(index: usize, item: &mut syn::Item) -> syn::Result<Self> {
pub fn try_from(_index: usize, item: &mut syn::Item) -> syn::Result<Self> {
let item_span = item.span();
let (vis, ident, generics) = match &item {
syn::Item::Enum(item) => (&item.vis, &item.ident, &item.generics),
Expand All @@ -46,7 +43,6 @@ impl OriginDef {
},
};

let has_instance = generics.params.len() == 2;
let is_generic = !generics.params.is_empty();

let mut instances = vec![];
Expand All @@ -67,6 +63,6 @@ impl OriginDef {
return Err(syn::Error::new(ident.span(), msg))
}

Ok(OriginDef { index, has_instance, is_generic, instances })
Ok(OriginDef { is_generic, instances })
}
}
Loading
Loading