Skip to content

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

Open
@lalala-233

Description

@lalala-233

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-resolveArea: Name/path resolution done by `rustc_resolve` specificallyC-discussionCategory: Discussion or questions that doesn't represent real issues.T-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