Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support reexport for procedural macros #2124

Merged
merged 2 commits into from Apr 22, 2020

Conversation

taiki-e
Copy link
Member

@taiki-e taiki-e commented Apr 10, 2020

Create a hidden module that reexports all items in the crate and import it at the beginning of the wrapper macro. This allows supporting not only rename but also reexport.

#[doc(hidden)]
pub mod __reexport {
    #[doc(hidden)]
    pub use crate::*;
}

#[doc(hidden)]
#[proc_macro_hack(support_nested)]
pub use futures_macro::join_internal;

#[macro_export]
macro_rules! join {
    ($($tokens:tt)*) => {{
        // The code generated by proc-macro uses a path starting with `__futures_crate`.
        // Also, `use $crate;` in macro is not allowed (https://github.com/rust-lang/rust/issues/37390),
        // so create hidden module `__reexport`.
        use $crate::__reexport as __futures_crate;
        $crate::join_internal! {
            $( $tokens )*
        }
    }}
}

Note that proc-macro is renamed to *_internal.
IIRC, it is not expected to use futures-macro directly, so this is probably fine...
(Maybe using = requirements would help to avoid some problems like #2061.)

Closes #2099

@cramertj
Copy link
Member

Nice, thanks for fixing this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cannot use macros when crate is renamed
2 participants