rust-lang / rust-lang/rust

pub use with glob import behaves differently when re-exported vs directly used

Open
#140,694 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-resolve C-discussion T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

I tried this code: Playground

mod foo {
    mod bar {
        pub(crate) fn foo() {
            println!("foo");
        }
    }
    // pub use bar::foo; // error[E0364]:`foo` is only public within the crate, and cannot be re-exported outside
    pub use bar::*;
}

fn main() {
    foo::foo();
}

I expected to see this happen:

When I use glob imports, I expected to import all importable entities that I can pub use to import directly.

Instead, this happened:

I can use foo::foo() because it is re-exported.

And compiler and clippy(-W clippy::nursery) give many warnings.

Meta

rustc --version --verbose:

rustc 1.86.0 (05f9846f8 2025-03-31) (Arch Linux rust 1:1.86.0-1)
binary: rustc
commit-hash: 05f9846f893b09a1be1fc8560e33fc3c815cfecb
commit-date: 2025-03-31
host: x86_64-unknown-linux-gnu
release: 1.86.0
LLVM version: 19.1.7

Some related link:

https://doc.rust-lang.org/reference/items/use-declarations.html#glob-imports

https://doc.rust-lang.org/error_codes/E0365.html

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked Playground reproducer and the Reference section on glob imports, then compare the direct pub use case with pub use bar::* and error E0364. Done means the compiler's handling of importable crate-private items is made consistent, with the reported warnings addressed and regression coverage added.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.