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

Macro import does not bring dependent macros in scope in 2018 edition #53811

Closed
starkat99 opened this issue Aug 30, 2018 · 2 comments
Closed

Comments

@starkat99
Copy link
Contributor

Importing a macro from a crate in 2018 edition that invokes other macros does not bring those macros in scope. It's easy enough to make work by importing the other macros of course, but surprising behavior anyway, especially when it involves importing macros that won't actually be referenced anywhere in the file itself, only through invocations.

Example (using clap 2.32):

use clap::app_from_crate;
fn main() {
    let _args = app_from_crate!().get_matches();
}

will produce the following error

error: cannot find macro `crate_name!` in this scope
 --> src\main.rs:5:17
  |
5 |     let _args = app_from_crate!().get_matches();
  |                 ^^^^^^^^^^^^^^^^^
  |
  = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
@Arnavion
Copy link

Arnavion commented Aug 31, 2018

I believe this is by design for macro_rules macros. Macros 2.0 are the only ones that have def-site-scoped dependencies.

Edit: The alternative is that clap annotates the dependency macros with local_inner_macros, as described in #51496

@jonas-schievink
Copy link
Contributor

local_inner_macros seems to fix this, so closing.

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

No branches or pull requests

3 participants