@@ -37,6 +37,7 @@ mod storage_alias;
37
37
mod transactional;
38
38
mod tt_macro;
39
39
40
+ use frame_support_procedural_tools:: generate_crate_access_2018;
40
41
use macro_magic:: import_tokens_attr;
41
42
use proc_macro:: TokenStream ;
42
43
use quote:: { quote, ToTokens } ;
@@ -952,28 +953,6 @@ pub fn storage_alias(_: TokenStream, input: TokenStream) -> TokenStream {
952
953
///
953
954
/// # Advanced Usage
954
955
///
955
- /// ## Importing & Re-Exporting
956
- ///
957
- /// Since `#[derive_impl(..)]` is a
958
- /// [`macro_magic`](https://docs.rs/macro_magic/latest/macro_magic/)-based attribute macro, special
959
- /// care must be taken when importing and re-exporting it. Glob imports will work properly, such as
960
- /// `use frame_support::*` to bring `derive_impl` into scope, however any other use statements
961
- /// involving `derive_impl` should have
962
- /// [`#[macro_magic::use_attr]`](https://docs.rs/macro_magic/latest/macro_magic/attr.use_attr.html)
963
- /// attached or your use statement will fail to fully bring the macro into scope.
964
- ///
965
- /// This brings `derive_impl` into scope in the current context:
966
- /// ```ignore
967
- /// #[use_attr]
968
- /// use frame_support::derive_impl;
969
- /// ```
970
- ///
971
- /// This brings `derive_impl` into scope and publicly re-exports it from the current context:
972
- /// ```ignore
973
- /// #[use_attr]
974
- /// pub use frame_support::derive_impl;
975
- /// ```
976
- ///
977
956
/// ## Expansion
978
957
///
979
958
/// 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 {
987
966
/// Items that lack a `syn::Ident` for whatever reason are first checked to see if they exist,
988
967
/// verbatim, in the local/destination trait before they are copied over, so you should not need to
989
968
/// worry about collisions between identical unnamed items.
990
- #[ import_tokens_attr( frame_support:: macro_magic) ]
969
+ #[ import_tokens_attr {
970
+ format!(
971
+ "{}::macro_magic" ,
972
+ match generate_crate_access_2018( "frame-support" ) {
973
+ Ok ( path) => Ok ( path) ,
974
+ Err ( _) => generate_crate_access_2018( "frame" ) ,
975
+ }
976
+ . expect( "Failed to find either `frame-support` or `frame` in `Cargo.toml` dependencies." )
977
+ . to_token_stream( )
978
+ . to_string( )
979
+ )
980
+ } ]
991
981
#[ with_custom_parsing( derive_impl:: DeriveImplAttrArgs ) ]
992
982
#[ proc_macro_attribute]
993
983
pub fn derive_impl ( attrs : TokenStream , input : TokenStream ) -> TokenStream {
@@ -1034,8 +1024,41 @@ pub fn no_default(_: TokenStream, _: TokenStream) -> TokenStream {
1034
1024
/// type MaxConsumers = frame_support::traits::ConstU32<16>;
1035
1025
/// }
1036
1026
/// ```
1027
+ ///
1028
+ /// ## Advanced Usage
1029
+ ///
1037
1030
/// This macro acts as a thin wrapper around macro_magic's `#[export_tokens]`. See the docs
1038
- /// [here](https://docs.rs/macro_magic/latest/macro_magic/attr.export_tokens.html) for more info.
1031
+ /// [here](https://docs.rs/macro_magic/latest/macro_magic/attr.export_tokens.html) for more
1032
+ /// info.
1033
+ ///
1034
+ /// There are some caveats when applying a `use` statement to bring a
1035
+ /// `#[register_default_impl]` item into scope. If you have a `#[register_default_impl]`
1036
+ /// defined in `my_crate::submodule::MyItem`, it is currently not sufficient to do something
1037
+ /// like:
1038
+ ///
1039
+ /// ```ignore
1040
+ /// use my_crate::submodule::MyItem;
1041
+ /// #[derive_impl(MyItem as Whatever)]
1042
+ /// ```
1043
+ ///
1044
+ /// This will fail with a mysterious message about `__export_tokens_tt_my_item` not being
1045
+ /// defined.
1046
+ ///
1047
+ /// You can, however, do any of the following:
1048
+ /// ```ignore
1049
+ /// // partial path works
1050
+ /// use my_crate::submodule;
1051
+ /// #[derive_impl(submodule::MyItem as Whatever)]
1052
+ /// ```
1053
+ /// ```ignore
1054
+ /// // full path works
1055
+ /// #[derive_impl(my_crate::submodule::MyItem as Whatever)]
1056
+ /// ```
1057
+ /// ```ignore
1058
+ /// // wild-cards work
1059
+ /// use my_crate::submodule::*;
1060
+ /// #[derive_impl(MyItem as Whatever)]
1061
+ /// ```
1039
1062
#[ proc_macro_attribute]
1040
1063
pub fn register_default_impl ( attrs : TokenStream , tokens : TokenStream ) -> TokenStream {
1041
1064
// ensure this is a impl statement
0 commit comments