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

False positive #[warn(unused_imports)] warning while glob importing macros defined in nested modules #115966

Closed
datasone opened this issue Sep 19, 2023 · 1 comment · Fixed by #115993
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug. D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@datasone
Copy link

I tried this code:

mod a {
    mod b {
        macro_rules! macro_b {
            () => {
                "Hello, world!"
            };
        }
        pub(crate) use macro_b;
    }
    pub use self::b::*;
}

fn main() {
    println!("{}", a::macro_b!());
}

I expected to see this happen: No warning generated

Instead, this happened: cargo check generated such warning

warning: glob import doesn't reexport anything because no candidate is public enough
  --> src/main.rs:10:13
   |
10 |     pub use self::b::*;
   |             ^^^^^^^^^^
   |
   = note: `#[warn(unused_imports)]` on by default

Though the warning says that glob import doesn't reexport anything, commenting out this line leads to error:

error[E0433]: failed to resolve: could not find `macro_b` in `a`
  --> src/main.rs:14:23
   |
14 |     println!("{}", a::macro_b!());
   |                       ^^^^^^^ could not find `macro_b` in `a`

warning: unused macro definition: `macro_b`
 --> src/main.rs:3:22
  |
3 |         macro_rules! macro_b {
  |                      ^^^^^^^
  |
  = note: `#[warn(unused_macros)]` on by default

warning: unused import: `macro_b`
 --> src/main.rs:8:24
  |
8 |         pub(crate) use macro_b;
  |                        ^^^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

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

The warning will not be generated when any other pub functions are added into module b and exported. It happens when the module only exports macros.

Meta

rustc --version --verbose:

rustc 1.74.0-nightly (65ea825f4 2023-09-18)
binary: rustc
commit-hash: 65ea825f4021eaf77f1b25139969712d65b435a4
commit-date: 2023-09-18
host: x86_64-unknown-linux-gnu
release: 1.74.0-nightly
LLVM version: 17.0.0
@datasone datasone added the C-bug Category: This is a bug. label Sep 19, 2023
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Sep 19, 2023
@eopb
Copy link
Contributor

eopb commented Sep 19, 2023

@rustbot label T-compiler A-diagnostics D-incorrect

@rustbot rustbot added A-diagnostics Area: Messages for errors, warnings, and lints D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Sep 19, 2023
@saethlin saethlin removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Sep 19, 2023
@bors bors closed this as completed in 64d7e0d Dec 1, 2023
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 C-bug Category: This is a bug. D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants