update macro_magic to 0.4.1 (#14356)

* update to macro_magic 0.4.0

* remove deprecated syntax and related doc comments

* upgrade to macro_magic v0.4.1

* fix import issue

* fix UI tests

* resolve frame_support path properly

* add docs note about importing

* fix typo

* Update frame/support/procedural/src/lib.rs

Co-authored-by: Guillaume Yu Thiolliere <gui.thiolliere@gmail.com>

* revert UI tests changes because we can't use rust 1.70

* fix UI tests

* fix another UI test

* use simplified import style

* switch back import since tests are written expecting it that way

---------

Co-authored-by: Guillaume Yu Thiolliere <gui.thiolliere@gmail.com>
This commit is contained in:
Sam Johnson
2023-06-16 09:06:28 -04:00
committed by GitHub
parent 1453bc9a2d
commit 18df38a4b6
9 changed files with 65 additions and 72 deletions
+1 -1
View File
@@ -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 }
@@ -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]
+47 -24
View File
@@ -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};
@@ -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
@@ -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()
)
}]
#[with_custom_parsing(derive_impl::DeriveImplAttrArgs)]
#[proc_macro_attribute]
pub fn derive_impl(attrs: TokenStream, input: TokenStream) -> TokenStream {
@@ -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
-1
View File
@@ -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.
@@ -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 {}
| ^^^^^^
@@ -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`