Skip to content

Nested import suggestion should maintain the same visibility level #141134

@bvanjoi

Description

@bvanjoi

Code

#[allow(unused_imports)]
mod a {
  #[macro_export]
  macro_rules! m {
      () => {};
  }
  pub struct S;
  mod b0 {
    pub use super::{m, S};
  }
}

fn main() {}

Current output

error[E0432]: unresolved import `super::m`
 --> crates/a/src/main.rs:9:21
  |
9 |     pub use super::{m, S};
  |                     ^ no `m` in `a`
  |
  = 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
  |
9 ~     use ::m;
10~ pub use super::{S};

Desired output

error[E0432]: unresolved import `super::m`
 --> crates/a/src/main.rs:9:21
  |
9 |     pub use super::{m, S};
  |                     ^ no `m` in `a`
  |
  = 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
  |
- 9 ~ use ::m;
+ 9~  pub use ::m;
10~ pub use super::{S};

Rationale and extra context

No response

Other cases

#[allow(unused_imports)]
mod a {
  #[macro_export]
  macro_rules! m {
      () => {};
  }
  pub struct S;
  mod b0 {
    pub use super::{m, S};
  }

  mod b1 {
    pub(crate) use super::{m, S};
  }

  mod b2 {
    pub(in crate::a) use super::{m, S};
  }

  mod b3 {
    pub(super) use super::{m, S};
  }

  mod b4 {
    pub(self) use super::{m, S};
  }

  mod b5 {
    use super::{m, S}; // the correct case
  }
}

Rust Version

rustc 1.89.0-nightly (16d2276fa 2025-05-16)
binary: rustc
commit-hash: 16d2276fa6fccb0cc239a542d4c3f0eb46f660ec
commit-date: 2025-05-16
host: aarch64-apple-darwin
release: 1.89.0-nightly
LLVM version: 20.1.4

Anything else?

No response

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions