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

Cannot use macros when crate is renamed #2099

Closed
That3Percent opened this issue Mar 16, 2020 · 5 comments · Fixed by #2124
Closed

Cannot use macros when crate is renamed #2099

That3Percent opened this issue Mar 16, 2020 · 5 comments · Fixed by #2124
Labels
A-macro Area: macro related

Comments

@That3Percent
Copy link

When the futures crate is renamed:

futures03 = { version = "0.3.1", package = "futures" }

Macros like try_join cannot find the crate.
Eg:

async fn test() {
    futures03::try_join!()
}

fails with

failed to resolve: could not find `futures` in `{{root}}`

This impedes migration from version 0.1 to version 0.3, since one of the two futures crates must be renamed.

@cramertj
Copy link
Member

This is known, but in general there's no way to solve this for procedural macros (at least that I know of). @dtolnay may know if there have been any recent innovations here?

@That3Percent
Copy link
Author

@cramertj This crate claims to solve this problem, but I have not tried it myself - https://crates.io/crates/proc-macro-crate

@dtolnay
Copy link
Member

dtolnay commented Mar 17, 2020

I definitely do not recommend using proc-macro-crate. It's based on parsing a Cargo.toml at macro expansion time so it breaks non-Cargo builds.

I think this is possible to make work correctly but I don't know if anyone has done it yet. Conceivably the try_join! macro invoked by the user could be a macro_rules macro that passes a $crate token to an underlying procedural macro.

@cramertj
Copy link
Member

@dtolnay I believe I tried that in the past and found that $crate passed to a procedural macro didn't resolve correctly. Could be worth trying again, though, as I don't remember precisely.

@taiki-e
Copy link
Member

taiki-e commented Apr 10, 2020

Conceivably the try_join! macro invoked by the user could be a macro_rules macro that passes a $crate token to an underlying procedural macro.

I think this probably works, but I found a way to support not only rename but also reexport, so I filed #2124.

EDIT: this seems to work after rust-lang/rust#57155

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-macro Area: macro related
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants