Skip to content

Commit 294e998

Browse files
authored
Fixes path issue in derive-impl (#1823)
Needs sam0x17/macro_magic#13 The associated PR allows the export of tokens from macro_magic at the specified path. This fixes the path issue in derive-impl. Now, we can import the default config using the standard rust syntax: ```rust use frame_system::config_preludes::TestDefaultConfig; [derive_impl(TestDefaultConfig as frame_system::DefaultConfig)] impl frame_system::DefaultConfig for Test { //.... } ```
1 parent 5adcb3e commit 294e998

File tree

4 files changed

+11
-12
lines changed

4 files changed

+11
-12
lines changed

substrate/frame/examples/default-config/src/lib.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
//! Study the following types:
2727
//!
2828
//! - [`pallet::DefaultConfig`], and how it differs from [`pallet::Config`].
29-
//! - [`pallet::config_preludes::TestDefaultConfig`] and how it implements
29+
//! - [`struct@pallet::config_preludes::TestDefaultConfig`] and how it implements
3030
//! [`pallet::DefaultConfig`].
3131
//! - Notice how [`pallet::DefaultConfig`] is independent of [`frame_system::Config`].
3232
@@ -83,11 +83,12 @@ pub mod pallet {
8383
// This will help use not need to disambiguate anything when using `derive_impl`.
8484
use super::*;
8585
use frame_support::derive_impl;
86+
use frame_system::config_preludes::TestDefaultConfig as SystemTestDefaultConfig;
8687

8788
/// A type providing default configurations for this pallet in testing environment.
8889
pub struct TestDefaultConfig;
8990

90-
#[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig, no_aggregated_types)]
91+
#[derive_impl(SystemTestDefaultConfig as frame_system::DefaultConfig, no_aggregated_types)]
9192
impl frame_system::DefaultConfig for TestDefaultConfig {}
9293

9394
#[frame_support::register_default_impl(TestDefaultConfig)]
@@ -109,7 +110,7 @@ pub mod pallet {
109110
/// example, we simple derive `frame_system::config_preludes::TestDefaultConfig` again.
110111
pub struct OtherDefaultConfig;
111112

112-
#[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig, no_aggregated_types)]
113+
#[derive_impl(SystemTestDefaultConfig as frame_system::DefaultConfig, no_aggregated_types)]
113114
impl frame_system::DefaultConfig for OtherDefaultConfig {}
114115

115116
#[frame_support::register_default_impl(OtherDefaultConfig)]

substrate/frame/support/procedural/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ mod transactional;
3434
mod tt_macro;
3535

3636
use frame_support_procedural_tools::generate_crate_access_2018;
37-
use macro_magic::import_tokens_attr;
37+
use macro_magic::{import_tokens_attr, import_tokens_attr_verbatim};
3838
use proc_macro::TokenStream;
3939
use quote::{quote, ToTokens};
4040
use std::{cell::RefCell, str::FromStr};
@@ -751,7 +751,7 @@ pub fn storage_alias(attributes: TokenStream, input: TokenStream) -> TokenStream
751751
/// Items that lack a `syn::Ident` for whatever reason are first checked to see if they exist,
752752
/// verbatim, in the local/destination trait before they are copied over, so you should not need to
753753
/// worry about collisions between identical unnamed items.
754-
#[import_tokens_attr {
754+
#[import_tokens_attr_verbatim {
755755
format!(
756756
"{}::macro_magic",
757757
match generate_crate_access_2018("frame-support") {
@@ -868,7 +868,7 @@ pub fn register_default_impl(attrs: TokenStream, tokens: TokenStream) -> TokenSt
868868
attrs,
869869
item_impl.to_token_stream(),
870870
true,
871-
true,
871+
false,
872872
) {
873873
Ok(tokens) => tokens.into(),
874874
Err(err) => err.to_compile_error().into(),
Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
error: cannot find macro `__export_tokens_tt_tiger` in this scope
2-
--> tests/derive_impl_ui/bad_default_impl_path.rs:59:1
1+
error: cannot find macro `Tiger` in this scope
2+
--> tests/derive_impl_ui/bad_default_impl_path.rs:59:15
33
|
44
59 | #[derive_impl(Tiger as Animal)]
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6-
|
7-
= note: this error originates in the macro `frame_support::macro_magic::forward_tokens` (in Nightly builds, run with -Z macro-backtrace for more info)
5+
| ^^^^^

substrate/frame/support/test/tests/derive_impl_ui/inject_runtime_type_fails_when_type_not_in_scope.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ error[E0412]: cannot find type `RuntimeCall` in this scope
77
35 | #[derive_impl(Pallet)] // Injects type RuntimeCall = RuntimeCall;
88
| ---------------------- in this macro invocation
99
|
10-
= note: this error originates in the macro `__export_tokens_tt_pallet` which comes from the expansion of the macro `frame_support::macro_magic::forward_tokens` (in Nightly builds, run with -Z macro-backtrace for more info)
10+
= note: this error originates in the macro `Pallet` which comes from the expansion of the macro `frame_support::macro_magic::forward_tokens_verbatim` (in Nightly builds, run with -Z macro-backtrace for more info)

0 commit comments

Comments
 (0)