rust-lang / rust-lang/rust

E0603 : constant import ... is private gives incrorrect suggestions

Open
#149,418 0 comments 0 reactions 1 assignee View on GitHub

@chenyukang is already working on this.

Since Jul 7, 2026.

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

Description

Code
mod delicious_snacks {
    use self::fruits::PEAR as fruit;

    mod fruits {
        pub const PEAR: &str = "Pear";
        pub const APPLE: &str = "Apple";
    }
}

fn main() {
    println!("favorite snack: {} ", delicious_snacks::fruit,);
}
Current output
error[E0603]: constant import `fruit` is private
  --> src/main.rs:11:55
   |
11 |     println!("favorite snack: {} ", delicious_snacks::fruit,);
   |                                                       ^^^^^ private constant import
   |
note: the constant import `fruit` is defined here...
  --> src/main.rs:2:9
   |
 2 |     use self::fruits::PEAR as fruit;
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: ...and refers to the constant `PEAR` which is defined here
  --> src/main.rs:5:9
   |
 5 |         pub const PEAR: &str = "Pear";
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ you could import this directly
help: import `fruit` through the re-export
   |
11 -     println!("favorite snack: {} ", delicious_snacks::fruit,);
11 +     println!("favorite snack: {} ", fruits::fruit,);
   |
Desired output
error[E0603]: constant import `fruit` is private
  --> src/main.rs:11:55
   |
11 |     println!("favorite snack: {} ", delicious_snacks::fruit,);
   |                                                       ^^^^^ private constant import
   |
note: the constant import `fruit` is defined here...
  --> src/main.rs:2:9
   |
 2 |     use self::fruits::PEAR as fruit;
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: ...and refers to the constant `PEAR` which is defined here
  --> src/main.rs:5:9
   |
 5 |         pub const PEAR: &str = "Pear";
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
help: consider making the constant `fruit` public
   |
 2 -     use self::fruits::PEAR as fruit;
 2 +     pub use self::fruits::PEAR as fruit;
   |     ^^^
Rationale and extra context

the "you could import this directly" is incorrect, maybe not as important.

having no help could be fine.

the help message is wrong in 2 important ways :

  • the fruits module does not have a fruit constant. (it got confused by the alias)
  • the fruits module is not accessible from line 11
Rust Version
rustc 1.91.1 (ed61e7d7e 2025-11-07)
binary: rustc
commit-hash: ed61e7d7e242494fb7057f2657300d9e77bb4fcb
commit-date: 2025-11-07
host: x86_64-pc-windows-msvc
release: 1.91.1
LLVM version: 21.1.2

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.