From fdd519880e036131f97de3111432a1da2fdcf6cd Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Mon, 12 Jun 2023 23:51:03 -0400 Subject: [PATCH 01/14] update to macro_magic 0.4.0 --- Cargo.lock | 16 ++++++++-------- frame/support/Cargo.toml | 2 +- frame/support/procedural/Cargo.toml | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index dcc47433460ee..56c024ac277f9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4829,9 +4829,9 @@ dependencies = [ [[package]] name = "macro_magic" -version = "0.3.5" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a2d6d7fe4741b5621cf7c8048e472933877c7ea870cbf1420da55ea9f3bb08c" +checksum = "6c69f43a71689fa6366d0baec3595f401d415360eab35611ba747a1afea6fad8" dependencies = [ "macro_magic_core", "macro_magic_macros", @@ -4841,9 +4841,9 @@ dependencies = [ [[package]] name = "macro_magic_core" -version = "0.3.5" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3005604258419767cacc5989c2dd75263f8b33773dd680734f598eb88baf5370" +checksum = "50b4674779d0ba2555444c441b8972fa3222f6cea035b95a5bf31b5906c947a3" dependencies = [ "derive-syn-parse", "macro_magic_core_macros", @@ -4854,9 +4854,9 @@ dependencies = [ [[package]] name = "macro_magic_core_macros" -version = "0.3.5" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "de6267819c9042df1a9e62ca279e5a34254ad5dfdcb13ff988f560d75576e8b4" +checksum = "e12e215c668456190e8041a94c45326b9a9686379cff3a1b0d50a83d7c7be790" dependencies = [ "proc-macro2", "quote", @@ -4865,9 +4865,9 @@ dependencies = [ [[package]] name = "macro_magic_macros" -version = "0.3.5" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc7176ac15ab2ed7f335e2398f729b9562dae0c233705bc1e1e3acd8452d403d" +checksum = "43ba4456c27540f1fbb83bc24de4f3315a40f96ba56e473186551cc3b3e0c4ad" dependencies = [ "macro_magic_core", "quote", diff --git a/frame/support/Cargo.toml b/frame/support/Cargo.toml index 030a52485b0e5..ef39d06f4dad9 100644 --- a/frame/support/Cargo.toml +++ b/frame/support/Cargo.toml @@ -29,7 +29,7 @@ sp-staking = { version = "4.0.0-dev", default-features = false, path = "../../pr sp-weights = { version = "20.0.0", default-features = false, path = "../../primitives/weights" } sp-debug-derive = { default-features = false, path = "../../primitives/debug-derive" } tt-call = "1.0.8" -macro_magic = "0.3.5" +macro_magic = "0.4.0" frame-support-procedural = { version = "4.0.0-dev", default-features = false, path = "./procedural" } paste = "1.0" once_cell = { version = "1", default-features = false, optional = true } diff --git a/frame/support/procedural/Cargo.toml b/frame/support/procedural/Cargo.toml index a2823463c5d67..044dabe8199ad 100644 --- a/frame/support/procedural/Cargo.toml +++ b/frame/support/procedural/Cargo.toml @@ -24,7 +24,7 @@ quote = "1.0.28" syn = { version = "2.0.16", features = ["full"] } frame-support-procedural-tools = { version = "4.0.0-dev", path = "./tools" } proc-macro-warning = { version = "0.4.1", default-features = false } -macro_magic = { version = "0.3.5", features = ["proc_support"] } +macro_magic = { version = "0.4.0", features = ["proc_support"] } [features] default = ["std"] From 63d4edc2323701b596582b2334e77329aa26dce1 Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Tue, 13 Jun 2023 00:07:34 -0400 Subject: [PATCH 02/14] remove deprecated syntax and related doc comments --- frame/examples/default-config/src/lib.rs | 6 ------ frame/examples/kitchensink/src/tests.rs | 4 +--- frame/support/procedural/src/lib.rs | 22 ---------------------- frame/support/src/lib.rs | 1 - 4 files changed, 1 insertion(+), 32 deletions(-) diff --git a/frame/examples/default-config/src/lib.rs b/frame/examples/default-config/src/lib.rs index adb2469e92fd9..c77a2d6013229 100644 --- a/frame/examples/default-config/src/lib.rs +++ b/frame/examples/default-config/src/lib.rs @@ -106,12 +106,6 @@ pub mod pallet { #[cfg(any(test, doc))] pub mod tests { use super::*; - - use frame_support::macro_magic::use_attr; - // Because `derive_impl` is a [macro_magic](https://crates.io/crates/macro_magic) attribute - // macro, [`#[use_attr]`](`frame_support::macro_magic::use_attr`) must be attached to any use - // statement that brings it into scope. - #[use_attr] use frame_support::derive_impl; use super::pallet as pallet_default_config_example; diff --git a/frame/examples/kitchensink/src/tests.rs b/frame/examples/kitchensink/src/tests.rs index d6c0891df89d7..a8645bedcb7e1 100644 --- a/frame/examples/kitchensink/src/tests.rs +++ b/frame/examples/kitchensink/src/tests.rs @@ -18,9 +18,7 @@ //! Tests for pallet-example-kitchensink. use crate::*; -#[use_attr] -use frame_support::derive_impl; -use frame_support::{macro_magic::use_attr, parameter_types, traits::ConstU64}; +use frame_support::{derive_impl, parameter_types, traits::ConstU64}; use sp_runtime::BuildStorage; // Reexport crate as its pallet name for construct_runtime. use crate as pallet_example_kitchensink; diff --git a/frame/support/procedural/src/lib.rs b/frame/support/procedural/src/lib.rs index 84a8b37f92e06..867c26e4b9dd2 100644 --- a/frame/support/procedural/src/lib.rs +++ b/frame/support/procedural/src/lib.rs @@ -952,28 +952,6 @@ pub fn storage_alias(_: TokenStream, input: TokenStream) -> TokenStream { /// /// # Advanced Usage /// -/// ## Importing & Re-Exporting -/// -/// Since `#[derive_impl(..)]` is a -/// [`macro_magic`](https://docs.rs/macro_magic/latest/macro_magic/)-based attribute macro, special -/// care must be taken when importing and re-exporting it. Glob imports will work properly, such as -/// `use frame_support::*` to bring `derive_impl` into scope, however any other use statements -/// involving `derive_impl` should have -/// [`#[macro_magic::use_attr]`](https://docs.rs/macro_magic/latest/macro_magic/attr.use_attr.html) -/// attached or your use statement will fail to fully bring the macro into scope. -/// -/// This brings `derive_impl` into scope in the current context: -/// ```ignore -/// #[use_attr] -/// use frame_support::derive_impl; -/// ``` -/// -/// This brings `derive_impl` into scope and publicly re-exports it from the current context: -/// ```ignore -/// #[use_attr] -/// pub use frame_support::derive_impl; -/// ``` -/// /// ## Expansion /// /// The `#[derive_impl(default_impl_path as disambiguation_path)]` attribute will expand to the diff --git a/frame/support/src/lib.rs b/frame/support/src/lib.rs index 8c2fd4fb62e37..0f2b135eed323 100644 --- a/frame/support/src/lib.rs +++ b/frame/support/src/lib.rs @@ -210,7 +210,6 @@ impl TypeId for PalletId { /// ``` pub use frame_support_procedural::storage_alias; -#[macro_magic::use_attr] pub use frame_support_procedural::derive_impl; /// Create new implementations of the [`Get`](crate::traits::Get) trait. From 5109e8da7405d05e92af81998e3cf7851cf1eeaf Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Tue, 13 Jun 2023 09:18:52 -0400 Subject: [PATCH 03/14] upgrade to macro_magic v0.4.1 --- Cargo.lock | 16 ++++++++-------- frame/support/Cargo.toml | 2 +- frame/support/procedural/Cargo.toml | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 56c024ac277f9..a54b5409e0b0e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4829,9 +4829,9 @@ dependencies = [ [[package]] name = "macro_magic" -version = "0.4.0" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c69f43a71689fa6366d0baec3595f401d415360eab35611ba747a1afea6fad8" +checksum = "614b1304ab7877b499925b4dcc5223ff480f2646ad4db1ee7065badb8d530439" dependencies = [ "macro_magic_core", "macro_magic_macros", @@ -4841,9 +4841,9 @@ dependencies = [ [[package]] name = "macro_magic_core" -version = "0.4.0" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50b4674779d0ba2555444c441b8972fa3222f6cea035b95a5bf31b5906c947a3" +checksum = "a8d72c1b662d07b8e482c80d3a7fc4168e058b3bef4c573e94feb714b670f406" dependencies = [ "derive-syn-parse", "macro_magic_core_macros", @@ -4854,9 +4854,9 @@ dependencies = [ [[package]] name = "macro_magic_core_macros" -version = "0.4.0" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e12e215c668456190e8041a94c45326b9a9686379cff3a1b0d50a83d7c7be790" +checksum = "93d7d9e6e234c040dafc745c7592738d56a03ad04b1fa04ab60821deb597466a" dependencies = [ "proc-macro2", "quote", @@ -4865,9 +4865,9 @@ dependencies = [ [[package]] name = "macro_magic_macros" -version = "0.4.0" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43ba4456c27540f1fbb83bc24de4f3315a40f96ba56e473186551cc3b3e0c4ad" +checksum = "ffd19f13cfd2bfbd83692adfef8c244fe5109b3eb822a1fb4e0a6253b406cd81" dependencies = [ "macro_magic_core", "quote", diff --git a/frame/support/Cargo.toml b/frame/support/Cargo.toml index ef39d06f4dad9..5e1eb9dc3fe88 100644 --- a/frame/support/Cargo.toml +++ b/frame/support/Cargo.toml @@ -29,7 +29,7 @@ sp-staking = { version = "4.0.0-dev", default-features = false, path = "../../pr sp-weights = { version = "20.0.0", default-features = false, path = "../../primitives/weights" } sp-debug-derive = { default-features = false, path = "../../primitives/debug-derive" } tt-call = "1.0.8" -macro_magic = "0.4.0" +macro_magic = "0.4.1" frame-support-procedural = { version = "4.0.0-dev", default-features = false, path = "./procedural" } paste = "1.0" once_cell = { version = "1", default-features = false, optional = true } diff --git a/frame/support/procedural/Cargo.toml b/frame/support/procedural/Cargo.toml index 044dabe8199ad..5baf003f00c94 100644 --- a/frame/support/procedural/Cargo.toml +++ b/frame/support/procedural/Cargo.toml @@ -24,7 +24,7 @@ quote = "1.0.28" syn = { version = "2.0.16", features = ["full"] } frame-support-procedural-tools = { version = "4.0.0-dev", path = "./tools" } proc-macro-warning = { version = "0.4.1", default-features = false } -macro_magic = { version = "0.4.0", features = ["proc_support"] } +macro_magic = { version = "0.4.1", features = ["proc_support"] } [features] default = ["std"] From 9ac1861d896713c353f6aa2ea58430b90621d55a Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Tue, 13 Jun 2023 10:32:59 -0400 Subject: [PATCH 04/14] fix import issue --- frame/examples/default-config/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frame/examples/default-config/src/lib.rs b/frame/examples/default-config/src/lib.rs index c77a2d6013229..5112f3d72d59e 100644 --- a/frame/examples/default-config/src/lib.rs +++ b/frame/examples/default-config/src/lib.rs @@ -162,7 +162,7 @@ pub mod tests { } // Similarly, we use the defaults provided by own crate as well. - use pallet::config_preludes::TestDefaultConfig; + use pallet::config_preludes::*; #[derive_impl(TestDefaultConfig as pallet::DefaultConfig)] impl crate::pallet::Config for Test { // These two both cannot have defaults. From 52805ed7878ed531c1f899139a5f5855b3e06714 Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Tue, 13 Jun 2023 10:50:08 -0400 Subject: [PATCH 05/14] fix UI tests --- .../attached_to_non_impl.stderr | 16 +++------------- .../bad_disambiguation_path.stderr | 19 ++++--------------- 2 files changed, 7 insertions(+), 28 deletions(-) diff --git a/frame/support/test/tests/derive_impl_ui/attached_to_non_impl.stderr b/frame/support/test/tests/derive_impl_ui/attached_to_non_impl.stderr index 94aee2442513a..735fd7a628e77 100644 --- a/frame/support/test/tests/derive_impl_ui/attached_to_non_impl.stderr +++ b/frame/support/test/tests/derive_impl_ui/attached_to_non_impl.stderr @@ -1,15 +1,5 @@ error: expected `impl` - --> tests/derive_impl_ui/attached_to_non_impl.rs:24:1 + --> tests/derive_impl_ui/attached_to_non_impl.rs:39:1 | -24 | / #[register_default_impl(FourLeggedAnimal)] -25 | | impl Animal for FourLeggedAnimal { -26 | | type Locomotion = RunsOnFourLegs; -27 | | type Diet = Omnivore; -... | -37 | | -38 | | #[derive_impl(FourLeggedAnimal as Animal)] - | |_-----------------------------------------^ - | | - | in this procedural macro expansion - | - = note: this error originates in the macro `__import_tokens_attr_derive_impl_inner` which comes from the expansion of the attribute macro `derive_impl` (in Nightly builds, run with -Z macro-backtrace for more info) +39 | struct Something {} + | ^^^^^^ diff --git a/frame/support/test/tests/derive_impl_ui/bad_disambiguation_path.stderr b/frame/support/test/tests/derive_impl_ui/bad_disambiguation_path.stderr index dd098d82c1e9b..6fd4e431beb52 100644 --- a/frame/support/test/tests/derive_impl_ui/bad_disambiguation_path.stderr +++ b/frame/support/test/tests/derive_impl_ui/bad_disambiguation_path.stderr @@ -1,16 +1,5 @@ -error[E0433]: failed to resolve: use of undeclared type `Insect` - --> tests/derive_impl_ui/bad_disambiguation_path.rs:24:1 +error[E0405]: cannot find trait `Insect` in this scope + --> tests/derive_impl_ui/bad_disambiguation_path.rs:38:35 | -24 | / #[register_default_impl(FourLeggedAnimal)] -25 | | impl Animal for FourLeggedAnimal { -26 | | type Locomotion = RunsOnFourLegs; -27 | | type Diet = Omnivore; -... | -37 | | -38 | | #[derive_impl(FourLeggedAnimal as Insect)] - | | -----------------------------------------^ - | |_|________________________________________| - | | use of undeclared type `Insect` - | in this procedural macro expansion - | - = note: this error originates in the macro `__import_tokens_attr_derive_impl_inner` which comes from the expansion of the attribute macro `derive_impl` (in Nightly builds, run with -Z macro-backtrace for more info) +38 | #[derive_impl(FourLeggedAnimal as Insect)] + | ^^^^^^ not found in this scope From c58a633840104b8e0d5e0da2130a8798fad5b456 Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Tue, 13 Jun 2023 12:57:31 -0400 Subject: [PATCH 06/14] resolve frame_support path properly --- frame/support/procedural/src/lib.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/frame/support/procedural/src/lib.rs b/frame/support/procedural/src/lib.rs index 867c26e4b9dd2..88b596b0bcf7f 100644 --- a/frame/support/procedural/src/lib.rs +++ b/frame/support/procedural/src/lib.rs @@ -37,6 +37,7 @@ mod storage_alias; mod transactional; mod tt_macro; +use frame_support_procedural_tools::generate_crate_access_2018; use macro_magic::import_tokens_attr; use proc_macro::TokenStream; use quote::{quote, ToTokens}; @@ -965,7 +966,18 @@ pub fn storage_alias(_: TokenStream, input: TokenStream) -> TokenStream { /// Items that lack a `syn::Ident` for whatever reason are first checked to see if they exist, /// verbatim, in the local/destination trait before they are copied over, so you should not need to /// worry about collisions between identical unnamed items. -#[import_tokens_attr(frame_support::macro_magic)] +#[import_tokens_attr { + format!( + "{}::macro_magic", + match generate_crate_access_2018("frame-support") { + Ok(path) => Ok(path), + Err(_) => generate_crate_access_2018("frame"), + } + .expect("Failed to find either `frame-support` or `frame` in `Cargo.toml` dependencies.") + .to_token_stream() + .to_string() + ) +}] #[with_custom_parsing(derive_impl::DeriveImplAttrArgs)] #[proc_macro_attribute] pub fn derive_impl(attrs: TokenStream, input: TokenStream) -> TokenStream { From ac271ea7b4aecc72a1a41ea1930611fdc3119cfe Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Wed, 14 Jun 2023 09:27:09 -0400 Subject: [PATCH 07/14] add docs note about importing --- frame/support/procedural/src/lib.rs | 35 ++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/frame/support/procedural/src/lib.rs b/frame/support/procedural/src/lib.rs index 88b596b0bcf7f..658ac7a5f180d 100644 --- a/frame/support/procedural/src/lib.rs +++ b/frame/support/procedural/src/lib.rs @@ -1024,8 +1024,41 @@ pub fn no_default(_: TokenStream, _: TokenStream) -> TokenStream { /// type MaxConsumers = frame_support::traits::ConstU32<16>; /// } /// ``` +/// +/// ## Advanced Usage +/// /// This macro acts as a thin wrapper around macro_magic's `#[export_tokens]`. See the docs -/// [here](https://docs.rs/macro_magic/latest/macro_magic/attr.export_tokens.html) for more info. +/// [here](https://docs.rs/macro_magic/latest/macro_magic/attr.export_tokens.html) for more +/// info. +/// +/// There are some caveats when applying a `use` statement to bring a +/// `#[register_default_impl]` item into scope. If you have a `#[register_default_impl]` +/// defined in `my_crate::submodule::MyItem`, it is currently not sufficient to do something +/// like: +/// +/// ```ignore +/// use my_crate::submodule::MyItem; +/// #[derive_impl!(MyItem as Whatever)] +/// ``` +/// +/// This will fail with a mysterious message about `__export_tokens_tt_my_item_0` not being +/// defined. +/// +/// You can, however, do any of the following: +/// ```ignore +/// // partial path works +/// use my_crate::submodule; +/// #[derive_impl!(submodule::MyItem as Whatever)] +/// ``` +/// ```ignore +/// // full path works +/// #[derive_impl!(my_crate::submodule::MyItem as Whatever)] +/// ``` +/// ```ignore +/// // wild-cards work +/// use my_crate::submodule::*; +/// #[derive_impl!(MyItem as Whatever)] +/// ``` #[proc_macro_attribute] pub fn register_default_impl(attrs: TokenStream, tokens: TokenStream) -> TokenStream { // ensure this is a impl statement From 81d051a316e32747308cbb398d10bf28a71726da Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Wed, 14 Jun 2023 09:29:39 -0400 Subject: [PATCH 08/14] fix typo --- frame/support/procedural/src/lib.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/frame/support/procedural/src/lib.rs b/frame/support/procedural/src/lib.rs index 658ac7a5f180d..cd93cfecbd76d 100644 --- a/frame/support/procedural/src/lib.rs +++ b/frame/support/procedural/src/lib.rs @@ -1038,7 +1038,7 @@ pub fn no_default(_: TokenStream, _: TokenStream) -> TokenStream { /// /// ```ignore /// use my_crate::submodule::MyItem; -/// #[derive_impl!(MyItem as Whatever)] +/// #[derive_impl(MyItem as Whatever)] /// ``` /// /// This will fail with a mysterious message about `__export_tokens_tt_my_item_0` not being @@ -1048,16 +1048,16 @@ pub fn no_default(_: TokenStream, _: TokenStream) -> TokenStream { /// ```ignore /// // partial path works /// use my_crate::submodule; -/// #[derive_impl!(submodule::MyItem as Whatever)] +/// #[derive_impl(submodule::MyItem as Whatever)] /// ``` /// ```ignore /// // full path works -/// #[derive_impl!(my_crate::submodule::MyItem as Whatever)] +/// #[derive_impl(my_crate::submodule::MyItem as Whatever)] /// ``` /// ```ignore /// // wild-cards work /// use my_crate::submodule::*; -/// #[derive_impl!(MyItem as Whatever)] +/// #[derive_impl(MyItem as Whatever)] /// ``` #[proc_macro_attribute] pub fn register_default_impl(attrs: TokenStream, tokens: TokenStream) -> TokenStream { From f1e1c5acabecdc8c1c39c4a797d6a714c18364d6 Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Wed, 14 Jun 2023 12:24:38 -0400 Subject: [PATCH 09/14] Update frame/support/procedural/src/lib.rs Co-authored-by: Guillaume Yu Thiolliere --- frame/support/procedural/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frame/support/procedural/src/lib.rs b/frame/support/procedural/src/lib.rs index cd93cfecbd76d..01c0c90be56f5 100644 --- a/frame/support/procedural/src/lib.rs +++ b/frame/support/procedural/src/lib.rs @@ -1041,7 +1041,7 @@ pub fn no_default(_: TokenStream, _: TokenStream) -> TokenStream { /// #[derive_impl(MyItem as Whatever)] /// ``` /// -/// This will fail with a mysterious message about `__export_tokens_tt_my_item_0` not being +/// This will fail with a mysterious message about `__export_tokens_tt_my_item` not being /// defined. /// /// You can, however, do any of the following: From 917b4de678d72620ddfcfb91ce11f7b85301424a Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Thu, 15 Jun 2023 16:32:14 -0400 Subject: [PATCH 10/14] revert UI tests changes because we can't use rust 1.70 --- .../attached_to_non_impl.stderr | 16 +++++++++++++--- .../bad_disambiguation_path.stderr | 19 +++++++++++++++---- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/frame/support/test/tests/derive_impl_ui/attached_to_non_impl.stderr b/frame/support/test/tests/derive_impl_ui/attached_to_non_impl.stderr index 735fd7a628e77..94aee2442513a 100644 --- a/frame/support/test/tests/derive_impl_ui/attached_to_non_impl.stderr +++ b/frame/support/test/tests/derive_impl_ui/attached_to_non_impl.stderr @@ -1,5 +1,15 @@ error: expected `impl` - --> tests/derive_impl_ui/attached_to_non_impl.rs:39:1 + --> tests/derive_impl_ui/attached_to_non_impl.rs:24:1 | -39 | struct Something {} - | ^^^^^^ +24 | / #[register_default_impl(FourLeggedAnimal)] +25 | | impl Animal for FourLeggedAnimal { +26 | | type Locomotion = RunsOnFourLegs; +27 | | type Diet = Omnivore; +... | +37 | | +38 | | #[derive_impl(FourLeggedAnimal as Animal)] + | |_-----------------------------------------^ + | | + | in this procedural macro expansion + | + = note: this error originates in the macro `__import_tokens_attr_derive_impl_inner` which comes from the expansion of the attribute macro `derive_impl` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/frame/support/test/tests/derive_impl_ui/bad_disambiguation_path.stderr b/frame/support/test/tests/derive_impl_ui/bad_disambiguation_path.stderr index 6fd4e431beb52..dd098d82c1e9b 100644 --- a/frame/support/test/tests/derive_impl_ui/bad_disambiguation_path.stderr +++ b/frame/support/test/tests/derive_impl_ui/bad_disambiguation_path.stderr @@ -1,5 +1,16 @@ -error[E0405]: cannot find trait `Insect` in this scope - --> tests/derive_impl_ui/bad_disambiguation_path.rs:38:35 +error[E0433]: failed to resolve: use of undeclared type `Insect` + --> tests/derive_impl_ui/bad_disambiguation_path.rs:24:1 | -38 | #[derive_impl(FourLeggedAnimal as Insect)] - | ^^^^^^ not found in this scope +24 | / #[register_default_impl(FourLeggedAnimal)] +25 | | impl Animal for FourLeggedAnimal { +26 | | type Locomotion = RunsOnFourLegs; +27 | | type Diet = Omnivore; +... | +37 | | +38 | | #[derive_impl(FourLeggedAnimal as Insect)] + | | -----------------------------------------^ + | |_|________________________________________| + | | use of undeclared type `Insect` + | in this procedural macro expansion + | + = note: this error originates in the macro `__import_tokens_attr_derive_impl_inner` which comes from the expansion of the attribute macro `derive_impl` (in Nightly builds, run with -Z macro-backtrace for more info) From 78df6057ae4ea970856f03a8336297a14b976267 Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Thu, 15 Jun 2023 21:22:04 -0400 Subject: [PATCH 11/14] fix UI tests --- .../derive_impl_ui/attached_to_non_impl.stderr | 16 +++------------- .../bad_disambiguation_path.stderr | 17 +++-------------- .../test/tests/derive_no_bound_ui/eq.stderr | 3 --- 3 files changed, 6 insertions(+), 30 deletions(-) diff --git a/frame/support/test/tests/derive_impl_ui/attached_to_non_impl.stderr b/frame/support/test/tests/derive_impl_ui/attached_to_non_impl.stderr index 94aee2442513a..735fd7a628e77 100644 --- a/frame/support/test/tests/derive_impl_ui/attached_to_non_impl.stderr +++ b/frame/support/test/tests/derive_impl_ui/attached_to_non_impl.stderr @@ -1,15 +1,5 @@ error: expected `impl` - --> tests/derive_impl_ui/attached_to_non_impl.rs:24:1 + --> tests/derive_impl_ui/attached_to_non_impl.rs:39:1 | -24 | / #[register_default_impl(FourLeggedAnimal)] -25 | | impl Animal for FourLeggedAnimal { -26 | | type Locomotion = RunsOnFourLegs; -27 | | type Diet = Omnivore; -... | -37 | | -38 | | #[derive_impl(FourLeggedAnimal as Animal)] - | |_-----------------------------------------^ - | | - | in this procedural macro expansion - | - = note: this error originates in the macro `__import_tokens_attr_derive_impl_inner` which comes from the expansion of the attribute macro `derive_impl` (in Nightly builds, run with -Z macro-backtrace for more info) +39 | struct Something {} + | ^^^^^^ diff --git a/frame/support/test/tests/derive_impl_ui/bad_disambiguation_path.stderr b/frame/support/test/tests/derive_impl_ui/bad_disambiguation_path.stderr index dd098d82c1e9b..76cf1646c48d2 100644 --- a/frame/support/test/tests/derive_impl_ui/bad_disambiguation_path.stderr +++ b/frame/support/test/tests/derive_impl_ui/bad_disambiguation_path.stderr @@ -1,16 +1,5 @@ error[E0433]: failed to resolve: use of undeclared type `Insect` - --> tests/derive_impl_ui/bad_disambiguation_path.rs:24:1 + --> tests/derive_impl_ui/bad_disambiguation_path.rs:38:35 | -24 | / #[register_default_impl(FourLeggedAnimal)] -25 | | impl Animal for FourLeggedAnimal { -26 | | type Locomotion = RunsOnFourLegs; -27 | | type Diet = Omnivore; -... | -37 | | -38 | | #[derive_impl(FourLeggedAnimal as Insect)] - | | -----------------------------------------^ - | |_|________________________________________| - | | use of undeclared type `Insect` - | in this procedural macro expansion - | - = note: this error originates in the macro `__import_tokens_attr_derive_impl_inner` which comes from the expansion of the attribute macro `derive_impl` (in Nightly builds, run with -Z macro-backtrace for more info) +38 | #[derive_impl(FourLeggedAnimal as Insect)] + | ^^^^^^ use of undeclared type `Insect` diff --git a/frame/support/test/tests/derive_no_bound_ui/eq.stderr b/frame/support/test/tests/derive_no_bound_ui/eq.stderr index eb3345eede508..93a828d7ab040 100644 --- a/frame/support/test/tests/derive_no_bound_ui/eq.stderr +++ b/frame/support/test/tests/derive_no_bound_ui/eq.stderr @@ -7,6 +7,3 @@ error[E0277]: can't compare `Foo` with `Foo` = help: the trait `PartialEq` is not implemented for `Foo` note: required by a bound in `std::cmp::Eq` --> $RUST/core/src/cmp.rs - | - | pub trait Eq: PartialEq { - | ^^^^^^^^^^^^^^^ required by this bound in `Eq` From 23f00ca8cb6a019fd441e1d4d41f9b6484fd95d7 Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Thu, 15 Jun 2023 23:06:18 -0400 Subject: [PATCH 12/14] fix another UI test --- frame/support/test/tests/derive_no_bound_ui/eq.stderr | 3 +++ 1 file changed, 3 insertions(+) diff --git a/frame/support/test/tests/derive_no_bound_ui/eq.stderr b/frame/support/test/tests/derive_no_bound_ui/eq.stderr index 93a828d7ab040..eb3345eede508 100644 --- a/frame/support/test/tests/derive_no_bound_ui/eq.stderr +++ b/frame/support/test/tests/derive_no_bound_ui/eq.stderr @@ -7,3 +7,6 @@ error[E0277]: can't compare `Foo` with `Foo` = help: the trait `PartialEq` is not implemented for `Foo` note: required by a bound in `std::cmp::Eq` --> $RUST/core/src/cmp.rs + | + | pub trait Eq: PartialEq { + | ^^^^^^^^^^^^^^^ required by this bound in `Eq` From 58afd2d877bac7df2c1d42197d5a396c0221d298 Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Thu, 15 Jun 2023 23:15:48 -0400 Subject: [PATCH 13/14] use simplified import style --- frame/examples/default-config/src/lib.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/frame/examples/default-config/src/lib.rs b/frame/examples/default-config/src/lib.rs index 5112f3d72d59e..13565c8735fc6 100644 --- a/frame/examples/default-config/src/lib.rs +++ b/frame/examples/default-config/src/lib.rs @@ -162,8 +162,7 @@ pub mod tests { } // Similarly, we use the defaults provided by own crate as well. - use pallet::config_preludes::*; - #[derive_impl(TestDefaultConfig as pallet::DefaultConfig)] + #[derive_impl(pallet::config_preludes::TestDefaultConfig as pallet::DefaultConfig)] impl crate::pallet::Config for Test { // These two both cannot have defaults. type RuntimeEvent = RuntimeEvent; From 582b4540c75ed2a0addc45bd04534240c316e011 Mon Sep 17 00:00:00 2001 From: Sam Johnson Date: Fri, 16 Jun 2023 07:44:36 -0400 Subject: [PATCH 14/14] switch back import since tests are written expecting it that way --- frame/examples/default-config/src/lib.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/frame/examples/default-config/src/lib.rs b/frame/examples/default-config/src/lib.rs index 13565c8735fc6..5112f3d72d59e 100644 --- a/frame/examples/default-config/src/lib.rs +++ b/frame/examples/default-config/src/lib.rs @@ -162,7 +162,8 @@ pub mod tests { } // Similarly, we use the defaults provided by own crate as well. - #[derive_impl(pallet::config_preludes::TestDefaultConfig as pallet::DefaultConfig)] + use pallet::config_preludes::*; + #[derive_impl(TestDefaultConfig as pallet::DefaultConfig)] impl crate::pallet::Config for Test { // These two both cannot have defaults. type RuntimeEvent = RuntimeEvent;