Skip to content

import #[macro_export] from crate root help uses 2015 use syntax #99694

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

Open
CAD97 opened this issue Jul 24, 2022 · 1 comment
Open

import #[macro_export] from crate root help uses 2015 use syntax #99694

CAD97 opened this issue Jul 24, 2022 · 1 comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints D-edition Diagnostics: An error or lint that should account for edition differences. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@CAD97
Copy link
Contributor

CAD97 commented Jul 24, 2022

Given the following code: [playground]

mod m {
    #[macro_export]
    macro_rules! nu {
        {} => {};
    }

    pub use self::nu;
}

The current output is:

error[[E0432]](https://doc.rust-lang.org/nightly/error-index.html#E0432): unresolved import `self::nu`
 --> src/lib.rs:7:13
  |
7 |     pub use self::nu;
  |             ^^^^^^^^ no `nu` in `m`
  |
  = note: this could be because a macro annotated with `#[macro_export]` will be exported at the root of the crate instead of the module where it is defined
help: a macro with this name exists at the root of the crate
  |
7 |     pub use ::nu;
  |             ~~~~

For more information about this error, try `rustc --explain E0432`.

This is using the edition2015 syntax to import from the crate root, rather than the edition2018+ required crate::nu.

Related: #99695

@rustbot label +D-edition +D-invalid-suggestion

@CAD97 CAD97 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. labels Jul 24, 2022
@rustbot rustbot added D-edition Diagnostics: An error or lint that should account for edition differences. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. labels Jul 24, 2022
@CAD97
Copy link
Contributor Author

CAD97 commented Jul 24, 2022

In this case, the ideal solution is actually to write just pub use nu; and get the import from legacy-lexical-macro-scope into the namespace.

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 D-edition Diagnostics: An error or lint that should account for edition differences. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. 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

2 participants