mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-30 07:17:56 +00:00
Don't require module name in inherents (#6576)
* Start * Cleanup `construct_runtime!` * Add tests * Fix after merge * Update the docs
This commit is contained in:
@@ -279,18 +279,6 @@ impl ModulePartKeyword {
|
||||
Ident::new(self.name(), self.span())
|
||||
}
|
||||
|
||||
/// Returns `true` if this module part allows to have an argument.
|
||||
///
|
||||
/// For example `Inherent(Timestamp)`.
|
||||
fn allows_arg(&self) -> bool {
|
||||
Self::all_allow_arg().iter().any(|n| *n == self.name())
|
||||
}
|
||||
|
||||
/// Returns the names of all module parts that allow to have an argument.
|
||||
fn all_allow_arg() -> &'static [&'static str] {
|
||||
&["Inherent"]
|
||||
}
|
||||
|
||||
/// Returns `true` if this module part is allowed to have generic arguments.
|
||||
fn allows_generic(&self) -> bool {
|
||||
Self::all_generic_arg().iter().any(|n| *n == self.name())
|
||||
@@ -321,7 +309,6 @@ impl Spanned for ModulePartKeyword {
|
||||
pub struct ModulePart {
|
||||
pub keyword: ModulePartKeyword,
|
||||
pub generics: syn::Generics,
|
||||
pub args: Option<ext::Parens<ext::Punctuated<Ident, Token![,]>>>,
|
||||
}
|
||||
|
||||
impl Parse for ModulePart {
|
||||
@@ -339,27 +326,10 @@ impl Parse for ModulePart {
|
||||
);
|
||||
return Err(syn::Error::new(keyword.span(), msg));
|
||||
}
|
||||
let args = if input.peek(token::Paren) {
|
||||
if !keyword.allows_arg() {
|
||||
let syn::group::Parens { token: parens, .. } = syn::group::parse_parens(input)?;
|
||||
let valid_names = ModulePart::format_names(ModulePartKeyword::all_allow_arg());
|
||||
let msg = format!(
|
||||
"`{}` is not allowed to have arguments in parens. \
|
||||
Only the following modules are allowed to have arguments in parens: {}.",
|
||||
keyword.name(),
|
||||
valid_names,
|
||||
);
|
||||
return Err(syn::Error::new(parens.span, msg));
|
||||
}
|
||||
Some(input.parse()?)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
Ok(Self {
|
||||
keyword,
|
||||
generics,
|
||||
args,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user