Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Commit edbcc99

Browse files
committed
clean up + cargo fmt
1 parent f4a52ae commit edbcc99

File tree

8 files changed

+57
-52
lines changed

8 files changed

+57
-52
lines changed

frame/examples/basic/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -368,15 +368,15 @@ pub mod pallet {
368368
// Setting a constant config parameter from the runtime
369369
#[pallet::constant]
370370
#[pallet::no_default]
371-
// It is very unfortunate that we cannot have this have a default either, because it relies on `<Self as pallet_balances::Config>`
371+
// It is very unfortunate that we cannot have this have a default either, because it relies
372+
// on `<Self as pallet_balances::Config>`
372373
type MagicNumber: Get<Self::Balance>;
373374

374375
/// The overarching event type.
375376
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
376377

377378
/// Type representing the weight of this pallet
378379
type WeightInfo: WeightInfo;
379-
380380
}
381381

382382
// Simple declaration of the `Pallet` type. It is placeholder we use to implement traits and

frame/nomination-pools/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1171,7 +1171,7 @@ pub mod pallet {
11711171
use super::*;
11721172
use frame_support::traits::StorageVersion;
11731173
use frame_system::{ensure_signed, pallet_prelude::*};
1174-
use sp_core::parameter_types;
1174+
use sp_core::parameter_types;
11751175

11761176
/// The current storage version.
11771177
const STORAGE_VERSION: StorageVersion = StorageVersion::new(3);

frame/support/procedural/src/derive_impl.rs

+47-44
Original file line numberDiff line numberDiff line change
@@ -19,85 +19,88 @@
1919
2020
use frame_support_procedural_tools::generate_crate_access_2018;
2121
use proc_macro2::TokenStream;
22-
use quote::ToTokens;
23-
use syn::{punctuated::Punctuated, ItemImpl, Result, Token};
22+
use syn::{
23+
braced, bracketed,
24+
parse::{Parse, ParseStream},
25+
parse2,
26+
punctuated::Punctuated,
27+
token::{Brace, Bracket},
28+
Ident, ImplItem, ItemImpl, Result, Token, TypePath,
29+
};
2430

2531
mod keywords {
26-
syn::custom_keyword!(derive_impl);
27-
syn::custom_keyword!(partial_impl_block);
28-
syn::custom_keyword!(implementing_type);
29-
syn::custom_keyword!(type_items);
30-
syn::custom_keyword!(fn_items);
31-
syn::custom_keyword!(const_items);
32+
use syn::custom_keyword;
33+
34+
custom_keyword!(derive_impl);
35+
custom_keyword!(partial_impl_block);
36+
custom_keyword!(implementing_type);
37+
custom_keyword!(type_items);
38+
custom_keyword!(fn_items);
39+
custom_keyword!(const_items);
3240
}
3341

3442
pub struct DeriveImplDef {
3543
/// The partial impl block that the user provides. This should be interpreted as "override".
36-
partial_impl_block: syn::ItemImpl,
44+
partial_impl_block: ItemImpl,
3745
/// The full path to the type that can be used to receive defaults form.
38-
implementing_type: syn::TypePath,
46+
implementing_type: TypePath,
3947
/// All of the associated type items that we must eventually implement.
40-
type_items: Punctuated<syn::Ident, Token![,]>,
48+
type_items: Punctuated<Ident, Token![,]>,
4149
/// All of the function items that we must eventually implement.
42-
fn_items: Punctuated<syn::Ident, Token![,]>,
50+
fn_items: Punctuated<Ident, Token![,]>,
4351
/// All of the constant items that we must eventually implement.
44-
const_items: Punctuated<syn::Ident, Token![,]>,
52+
const_items: Punctuated<Ident, Token![,]>,
4553
}
4654

47-
impl syn::parse::Parse for DeriveImplDef {
48-
fn parse(input: syn::parse::ParseStream) -> Result<Self> {
55+
impl Parse for DeriveImplDef {
56+
fn parse(input: ParseStream) -> Result<Self> {
4957
// NOTE: unfortunately, the order the keywords here must match what the pallet macro
5058
// expands. We can probably used a shared set of keywords later.
5159
let mut partial_impl_block;
5260
let _ = input.parse::<keywords::partial_impl_block>()?;
53-
let _ = input.parse::<syn::Token![=]>()?;
54-
let _replace_with_bracket: syn::token::Bracket =
55-
syn::bracketed!(partial_impl_block in input);
56-
let _replace_with_brace: syn::token::Brace =
57-
syn::braced!(partial_impl_block in partial_impl_block);
61+
let _ = input.parse::<Token![=]>()?;
62+
let _replace_with_bracket: Bracket = bracketed!(partial_impl_block in input);
63+
let _replace_with_brace: Brace = braced!(partial_impl_block in partial_impl_block);
5864
let partial_impl_block = partial_impl_block.parse()?;
5965

6066
let mut implementing_type;
6167
let _ = input.parse::<keywords::implementing_type>()?;
62-
let _ = input.parse::<syn::Token![=]>()?;
63-
let _replace_with_bracket: syn::token::Bracket =
64-
syn::bracketed!(implementing_type in input);
65-
let _replace_with_brace: syn::token::Brace =
66-
syn::braced!(implementing_type in implementing_type);
68+
let _ = input.parse::<Token![=]>()?;
69+
let _replace_with_bracket: Bracket = bracketed!(implementing_type in input);
70+
let _replace_with_brace: Brace = braced!(implementing_type in implementing_type);
6771
let implementing_type = implementing_type.parse()?;
6872

6973
let mut type_items;
7074
let _ = input.parse::<keywords::type_items>()?;
71-
let _ = input.parse::<syn::Token![=]>()?;
72-
let _replace_with_bracket: syn::token::Bracket = syn::bracketed!(type_items in input);
73-
let _replace_with_brace: syn::token::Brace = syn::braced!(type_items in type_items);
74-
let type_items = Punctuated::<syn::Ident, Token![,]>::parse_terminated(&type_items)?;
75+
let _ = input.parse::<Token![=]>()?;
76+
let _replace_with_bracket: Bracket = bracketed!(type_items in input);
77+
let _replace_with_brace: Brace = braced!(type_items in type_items);
78+
let type_items = Punctuated::<Ident, Token![,]>::parse_terminated(&type_items)?;
7579

7680
let mut fn_items;
7781
let _ = input.parse::<keywords::fn_items>()?;
78-
let _ = input.parse::<syn::Token![=]>()?;
79-
let _replace_with_bracket: syn::token::Bracket = syn::bracketed!(fn_items in input);
80-
let _replace_with_brace: syn::token::Brace = syn::braced!(fn_items in fn_items);
81-
let fn_items = Punctuated::<syn::Ident, Token![,]>::parse_terminated(&fn_items)?;
82+
let _ = input.parse::<Token![=]>()?;
83+
let _replace_with_bracket: Bracket = bracketed!(fn_items in input);
84+
let _replace_with_brace: Brace = braced!(fn_items in fn_items);
85+
let fn_items = Punctuated::<Ident, Token![,]>::parse_terminated(&fn_items)?;
8286

8387
let mut const_items;
8488
let _ = input.parse::<keywords::const_items>()?;
85-
let _ = input.parse::<syn::Token![=]>()?;
86-
let _replace_with_bracket: syn::token::Bracket = syn::bracketed!(const_items in input);
87-
let _replace_with_brace: syn::token::Brace = syn::braced!(const_items in const_items);
88-
let const_items = Punctuated::<syn::Ident, Token![,]>::parse_terminated(&const_items)?;
89+
let _ = input.parse::<Token![=]>()?;
90+
let _replace_with_bracket: Bracket = bracketed!(const_items in input);
91+
let _replace_with_brace: Brace = braced!(const_items in const_items);
92+
let const_items = Punctuated::<Ident, Token![,]>::parse_terminated(&const_items)?;
8993

9094
Ok(Self { partial_impl_block, type_items, fn_items, const_items, implementing_type })
9195
}
9296
}
9397

9498
pub(crate) fn derive_impl_inner(input: TokenStream) -> Result<TokenStream> {
9599
println!("input: {}", input);
96-
let DeriveImplDef { partial_impl_block, implementing_type, type_items, .. } =
97-
syn::parse2(input)?;
100+
let DeriveImplDef { partial_impl_block, implementing_type, type_items, .. } = parse2(input)?;
98101

99-
let type_item_name = |i: &syn::ImplItem| {
100-
if let syn::ImplItem::Type(t) = i {
102+
let type_item_name = |i: &ImplItem| {
103+
if let ImplItem::Type(t) = i {
101104
t.ident.clone()
102105
} else {
103106
panic!("only support type items for now")
@@ -125,8 +128,8 @@ pub(crate) fn derive_impl_inner(input: TokenStream) -> Result<TokenStream> {
125128
} else {
126129
// add it
127130
let tokens = quote::quote!(type #ident = <#implementing_type as #source_crate_path::pallet::DefaultConfig>::#ident;);
128-
let parsed: syn::ImplItem = syn::parse2(tokens).expect("it is a valid type item");
129-
debug_assert!(matches!(parsed, syn::ImplItem::Type(_)));
131+
let parsed: ImplItem = parse2(tokens).expect("it is a valid type item");
132+
debug_assert!(matches!(parsed, ImplItem::Type(_)));
130133

131134
final_impl_block.items.push(parsed)
132135
}
@@ -136,7 +139,7 @@ pub(crate) fn derive_impl_inner(input: TokenStream) -> Result<TokenStream> {
136139
}
137140

138141
pub fn derive_impl(attrs: TokenStream, input: TokenStream) -> Result<TokenStream> {
139-
let implementing_type: syn::TypePath = syn::parse2(attrs.clone())?;
142+
let implementing_type: TypePath = parse2(attrs.clone())?;
140143
// ideas for sam:
141144
// let other_path_tokens = magic_macro!(path_to_other_path_token);
142145
// let foreign_trait_def_token: Syn::TraitItem = magic_macro!(frame_system::Config);

frame/support/procedural/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ mod construct_runtime;
2525
mod crate_version;
2626
mod debug_no_bound;
2727
mod default_no_bound;
28+
mod derive_impl;
2829
mod dummy_part_checker;
2930
mod key_prefix;
3031
mod match_and_insert;
@@ -35,7 +36,6 @@ mod storage;
3536
mod storage_alias;
3637
mod transactional;
3738
mod tt_macro;
38-
mod derive_impl;
3939

4040
use proc_macro::TokenStream;
4141
use quote::quote;

frame/support/procedural/src/pallet/expand/config.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ pub fn expand_config(def: &mut Def) -> proc_macro2::TokenStream {
5050
)
5151
.collect::<Vec<_>>();
5252

53-
// we rarely use const and fns in config traits anyways... maybe not supporting them is good enough.
53+
// we rarely use const and fns in config traits anyways... maybe not supporting them is good
54+
// enough.
5455
let const_names = Vec::<syn::Ident>::default();
5556
let fn_names = Vec::<syn::Ident>::default();
5657

frame/support/procedural/src/pallet/parse/helper.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ pub trait MutItemAttrs {
4747
}
4848

4949
/// Take the first pallet attribute (e.g. attribute like `#[pallet..]`) and decode it to `Attr`
50-
pub(crate) fn take_first_item_pallet_attr<Attr>(item: &mut impl MutItemAttrs) -> syn::Result<Option<Attr>>
50+
pub(crate) fn take_first_item_pallet_attr<Attr>(
51+
item: &mut impl MutItemAttrs,
52+
) -> syn::Result<Option<Attr>>
5153
where
5254
Attr: syn::parse::Parse,
5355
{

frame/support/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,6 @@ pub use frame_support_procedural::derive_impl;
215215
#[doc(hidden)]
216216
pub use frame_support_procedural::derive_impl_inner;
217217

218-
219218
/// Create new implementations of the [`Get`](crate::traits::Get) trait.
220219
///
221220
/// The so-called parameter type can be created in four different ways:

frame/system/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,8 @@ pub mod pallet {
205205
use super::*;
206206
pub mod testing {
207207
type AccountId = u64;
208-
use sp_runtime::traits::IdentityLookup;
209208
use super::*;
209+
use sp_runtime::traits::IdentityLookup;
210210

211211
pub struct Impl {}
212212
impl DefaultConfig for Impl {

0 commit comments

Comments
 (0)