Skip to content

Macros are not propagated through pub extern crate. #51530

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

Closed
Xaeroxe opened this issue Jun 13, 2018 · 11 comments
Closed

Macros are not propagated through pub extern crate. #51530

Xaeroxe opened this issue Jun 13, 2018 · 11 comments
Labels
P-high High priority regression-from-stable-to-stable Performance or correctness regression from one stable version to another. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Xaeroxe
Copy link
Contributor

Xaeroxe commented Jun 13, 2018

As of Rust 1.26.2 stable if I define an exported macro in crate foo then pub extern crate foo in another crate bar then consumers of the bar crate cannot use the macro in foo even if there is a #[macro_use] on the pub extern crate foo and a #[macro_use] on the extern crate bar in the consumers code.

I would expect the macros to be propagated similarly to the other items in the foo crate.

This can be worked around by having the consumer of bar depend on foo directly, but that defeats the purpose of the pub extern crate imo.

@Mark-Simulacrum Mark-Simulacrum added the regression-from-stable-to-stable Performance or correctness regression from one stable version to another. label Jun 13, 2018
@Mark-Simulacrum
Copy link
Member

cc @jseyfried @petrochenkov

I'm also nominating for compiler team discussion -- this feels like it might be somewhat related to recent movement on the use extern macros feature?

@Mark-Simulacrum Mark-Simulacrum added I-nominated T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 13, 2018
@Xaeroxe
Copy link
Contributor Author

Xaeroxe commented Jun 13, 2018

minimal-repro.zip

Here's a minimal reproduction case

@nikomatsakis
Copy link
Contributor

This is tagged as a regression, but did this ever work? Maybe my memory is faulty, but I didn't think that #[macro_use] worked across crates (no matter the privacy of the extern crate in question).

@nikomatsakis
Copy link
Contributor

Put another way, the behavior @Xaeroxe describes is the behavior I expect. I think that this was the purpose of #[macro_reexport] (#29638) which was never stabilized (and indeed was recently removed). We expect pub use to eventually play this role, modulo the resolution of the various issues around it.

@nikomatsakis
Copy link
Contributor

triage: P-high

Marking as P-high so that we revisit next week. But I'm not convinced this is a bug (as I wrote earlier).

Thoughts @rust-lang/compiler ?

@nikomatsakis nikomatsakis added P-high High priority and removed I-nominated labels Jun 21, 2018
@petrochenkov
Copy link
Contributor

Yes, this isn't supposed to work.
#[macro_use] extern crate ... adds macros to the prelude, but not reexports them in any way.
As @nikomatsakis said #[macro_reexport] was used for reexporting and now it's subsumed by pub use.

@nikomatsakis
Copy link
Contributor

Closing as not a bug, thanks @petrochenkov.

@MightyPork
Copy link

MightyPork commented Aug 26, 2019

I'm trying to use this feature and it doesn't work with pub use. Is there currently a working mechanism to reexport macros?

My use case is caused by the lack of workspace-wide dependency config in Cargo.toml, so I made a crate "deps" that was meant to reexport dependencies that need special feature flags or versions. It works fine, except for macros.

I tried pub use, pub extern crate, both with #[macro_use] and #[macro_export], and import it with #[macro_use]. Nothing got the macro into scope ("cannot find macro doc! in this scope")

@petrochenkov
Copy link
Contributor

@MightyPork
Could you give some example / reproduction?
pub use generally works for macros and is actively used (e.g. for reexporting macros from libcore in libstd).

@MightyPork
Copy link

here is a minimal reproduction (tested with current stable):

debug-macro-reexport.zip

@petrochenkov
Copy link
Contributor

@MightyPork
That example is supposed to use pub use bson::doc;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P-high High priority regression-from-stable-to-stable Performance or correctness regression from one stable version to another. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

5 participants