- Notifications
You must be signed in to change notification settings - Fork 14.1k
Open
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
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
fruitsmodule does not have afruitconstant. (it got confused by the alias) - the
fruitsmodule 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.2Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.