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

update macro_magic to 0.4.1 #14356

Merged
merged 16 commits into from
Jun 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 1 addition & 7 deletions frame/examples/default-config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -168,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.
Expand Down
4 changes: 1 addition & 3 deletions frame/examples/kitchensink/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion frame/support/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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.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 }
Expand Down
2 changes: 1 addition & 1 deletion frame/support/procedural/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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.1", features = ["proc_support"] }
expander = "2.0.0"

[features]
Expand Down
71 changes: 47 additions & 24 deletions frame/support/procedural/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -952,28 +953,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
Expand All @@ -987,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()
)
}]
sam0x17 marked this conversation as resolved.
Show resolved Hide resolved
#[with_custom_parsing(derive_impl::DeriveImplAttrArgs)]
#[proc_macro_attribute]
pub fn derive_impl(attrs: TokenStream, input: TokenStream) -> TokenStream {
Expand Down Expand Up @@ -1034,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` 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
Expand Down
1 change: 0 additions & 1 deletion frame/support/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {}
| ^^^^^^
Original file line number Diff line number Diff line change
@@ -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`