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

Allow proc-macro crates to export macro_rules macros #40090

Closed
SimonSapin opened this Issue Feb 25, 2017 · 4 comments

Comments

Projects
None yet
3 participants
@SimonSapin
Copy link
Contributor

SimonSapin commented Feb 25, 2017

In rustc 1.17.0-nightly (413a975 2017-02-23), this

#![crate_type = "proc-macro"]

#[macro_export]
macro_rules! foo {
    () => {}
}

causes a compiler error:

error: cannot export macro_rules! macros from a `proc-macro` crate type currently

As far as I understand, proc-macro crates can currently only export procedural macros because when cross-compiling they’re compiler for the host whereas "normal" crates are compiler for the target, and items such as functions or types defined in a proc-macro crate would also need to be compiler for the target when used (through a dependency) on a "normal" crate. But this is not a problem for macro_rules which is purely compile-time.

So it seems that lifting this restriction for macro_rules might require less implementation effort than lifting it for every kind of item?

@abonander

This comment has been minimized.

Copy link
Contributor

abonander commented Feb 25, 2017

Do plugin crates allow exporting macros? The implementation is similar.

@jseyfried jseyfried self-assigned this Feb 25, 2017

@jseyfried

This comment has been minimized.

Copy link
Contributor

jseyfried commented Feb 25, 2017

cc @nrc

@SimonSapin

This comment has been minimized.

Copy link
Contributor

SimonSapin commented Feb 28, 2017

I’ve realized that I can do this the other way around, which is even better: re-export procedural macros from a library crate:

// In cssparser’s lib.rs
#[macro_use] extern crate cssparser_macros;
pub use cssparser_macros::*;

Crates using this library only need one extern crate line:

// Import both cssparser_macros::* and macro_rules! macro exported by cssparser itself.
#[macro_use] extern crate cssparser;

Although it would be nice for this issue to be fixed eventually, for me the above removes any desire to see it prioritized.

@jseyfried

This comment has been minimized.

Copy link
Contributor

jseyfried commented Mar 2, 2017

I'm not sure this is a good idea in the first place -- since we don't allow exporting an item (e.g. pub fn) then I don't think we should allow exporting a macro_rules! either for symmetry.

Eventually, we might allow exporting arbitrary items, but we'll probably need a story for phases first (quite a ways down the road).

@jseyfried jseyfried closed this Mar 2, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment