mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-20 15:11:02 +00:00
Adds ability to provide defaults for types provided by construct_runtime (#14682)
* Adds ability to use defaults for verbatim types * Adds RuntimeOrigin and PalletInfo in DefaultConfig * Adds RuntimeEvent in DefaultConfig * Adds RuntimeEvent in DefaultConfig * Minor fix * Minor fix * Everything in frame_system can now have a default * Adds docs * Adds UI Test for no_bounds * Updates docs * Adds UI tests for verbatim * Minor update * Minor updates * Minor updates * Addresses review comments * Fixes test * Update frame/support/procedural/src/derive_impl.rs Co-authored-by: Keith Yeung <kungfukeith11@gmail.com> * Minor fix * Minor * Fixes build * Uses runtime_type * Fixes comment * Fixes comment * Fixes test * Uses no_aggregated_types as an option in derive_impl * Uses specific imports * Fmt * Updates doc * Update frame/support/procedural/src/derive_impl.rs Co-authored-by: Bastian Köcher <git@kchr.de> * Update frame/support/procedural/src/derive_impl.rs Co-authored-by: Bastian Köcher <git@kchr.de> * Addresses review comment * Addresses review comment * fmt * Renames test files * Adds docs using docify * Fixes test * Fixes UI tests --------- Co-authored-by: Keith Yeung <kungfukeith11@gmail.com> Co-authored-by: Bastian Köcher <git@kchr.de>
This commit is contained in:
@@ -34,12 +34,16 @@ mod keyword {
|
||||
syn::custom_keyword!(frame_system);
|
||||
syn::custom_keyword!(disable_frame_system_supertrait_check);
|
||||
syn::custom_keyword!(no_default);
|
||||
syn::custom_keyword!(no_default_bounds);
|
||||
syn::custom_keyword!(constant);
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct DefaultTrait {
|
||||
pub items: Vec<syn::TraitItem>,
|
||||
/// A bool for each sub-trait item indicates whether the item has
|
||||
/// `#[pallet::no_default_bounds]` attached to it. If true, the item will not have any bounds
|
||||
/// in the generated default sub-trait.
|
||||
pub items: Vec<(syn::TraitItem, bool)>,
|
||||
pub has_system: bool,
|
||||
}
|
||||
|
||||
@@ -142,6 +146,8 @@ impl syn::parse::Parse for DisableFrameSystemSupertraitCheck {
|
||||
pub enum PalletAttrType {
|
||||
#[peek(keyword::no_default, name = "no_default")]
|
||||
NoDefault(keyword::no_default),
|
||||
#[peek(keyword::no_default_bounds, name = "no_default_bounds")]
|
||||
NoBounds(keyword::no_default_bounds),
|
||||
#[peek(keyword::constant, name = "constant")]
|
||||
Constant(keyword::constant),
|
||||
}
|
||||
@@ -366,6 +372,7 @@ impl ConfigDef {
|
||||
|
||||
let mut already_no_default = false;
|
||||
let mut already_constant = false;
|
||||
let mut already_no_default_bounds = false;
|
||||
|
||||
while let Ok(Some(pallet_attr)) =
|
||||
helper::take_first_item_pallet_attr::<PalletAttr>(trait_item)
|
||||
@@ -403,15 +410,31 @@ impl ConfigDef {
|
||||
|
||||
already_no_default = true;
|
||||
},
|
||||
(PalletAttrType::NoBounds(_), _) => {
|
||||
if !enable_default {
|
||||
return Err(syn::Error::new(
|
||||
pallet_attr._bracket.span.join(),
|
||||
"`#[pallet:no_default_bounds]` can only be used if `#[pallet::config(with_default)]` \
|
||||
has been specified"
|
||||
))
|
||||
}
|
||||
if already_no_default_bounds {
|
||||
return Err(syn::Error::new(
|
||||
pallet_attr._bracket.span.join(),
|
||||
"Duplicate #[pallet::no_default_bounds] attribute not allowed.",
|
||||
))
|
||||
}
|
||||
already_no_default_bounds = true;
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
if !already_no_default && !is_event && enable_default {
|
||||
if !already_no_default && enable_default {
|
||||
default_sub_trait
|
||||
.as_mut()
|
||||
.expect("is 'Some(_)' if 'enable_default'; qed")
|
||||
.items
|
||||
.push(trait_item.clone());
|
||||
.push((trait_item.clone(), already_no_default_bounds));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user