rust-lang / rust-lang/rust

Incorrectly reporting a type alias as a public re-export

Open
#151,182 0 comments 0 reactions 1 assignee View on GitHub

@TaKO8Ki is already working on this.

Since Jan 17, 2026.

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

Description

Code
mod foo {
    pub type FooType = u32;
}

use foo::FooType; // Removing this line prevents the bug
mod bar {
    pub fn bar_func() {
        let val: FooType = 4;
    }
}

fn main() {
    bar::bar_func();
}
Current output
error[E0412]: cannot find type `FooType` in this scope
 --> test.rs:8:18
  |
8 |         let val: FooType = 4;
  |                  ^^^^^^^ not found in this scope
  |
help: consider importing this type alias through its public re-export
  |
7 +     use FooType;
  |
Desired output
error[E0412]: cannot find type `FooType` in this scope
 --> test.rs:8:18
  |
8 |         let val: FooType = 4;
  |                  ^^^^^^^ not found in this scope
  |
help: consider importing this type alias through a parent import
  |
7 +     use FooType;
  |
Rust Version
rustc 1.93.0-nightly (2286e5d22 2025-11-13)
binary: rustc
commit-hash: 2286e5d224b3413484cf4f398a9f078487e7b49d
commit-date: 2025-11-13
host: x86_64-unknown-linux-gnu
release: 1.93.0-nightly
LLVM version: 21.1.5
Anything else?

If I understand correctly, the compiler sees an import in the module tree that is closer than the original definition of the type. It assumes that it must be a public re-export, but it is only accessible in the bar scope because bar is a child of the module with the import - not because the import is public. Could be on the wrong track though.

I'm not sure whether the appropriate behavior in this situation is to recommend that the user import it from the original declaration (use super::foo::FooType) or continue to recommend the import from the root (use crate::FooType), but either way the type alias should not be labelled as a public re-export.

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.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.