Skip to content

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