Skip to content

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

@Morgane55440

Description

@Morgane55440

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

Metadata

Metadata

Assignees

No one assigned

    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