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

Warn about #[macro_export] mod m? #52371

Open
ralfbiedert opened this issue Jul 14, 2018 · 0 comments
Open

Warn about #[macro_export] mod m? #52371

ralfbiedert opened this issue Jul 14, 2018 · 0 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-macros-1.2 Area: Declarative macros 1.2 C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@ralfbiedert
Copy link
Contributor

ralfbiedert commented Jul 14, 2018

I haven't used macros that often, but had to make changes in a 3rd party project.

During refactoring I tried to import macros from another module. I knew I had to add macro_use, macro_export somehow, but couldn't remember details.

While rustc was somewhat helpful in warning me on my first attempt:

error: cannot find macro `test!` in this scope
 --> src/x/u/u.rs:5:1
  |
5 | test! {
  | ^^^^^^^^^^
  |
  = help: have you added the `#[macro_use]` on the module/import?

It did not warn me about doing this:

#[macro_export] 
mod m;

where in reality I should have done that:

#[macro_use] 
mod m;

This was particularly confusing since the used macro was a few modules down in the hierarchy, and I should have done #[macro_use] on each level. Since I wasn't warned, I assumed #[macro_export] mod m; was correct. Instead, I tried a few permutations adding #[macro_use] to other places, which all didn't work out.

Two things that would have worked for me:

  • Warn about #[macro_export] mod m;
  • Make the help text above more explicit, e.g., by suggesting that macro_use needs to be added to all parent modules (maybe with a link to the error index)

Update: using rustc 1.29.0-nightly (9fd3d7899 2018-07-07)

@jonas-schievink jonas-schievink added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-macros-1.2 Area: Declarative macros 1.2 labels Jan 27, 2019
@crlf0710 crlf0710 added the C-enhancement Category: An issue proposing an enhancement or a PR with one. label Jun 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-macros-1.2 Area: Declarative macros 1.2 C-enhancement Category: An issue proposing an enhancement or a PR with one. 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

3 participants