- Notifications
You must be signed in to change notification settings - Fork 13.8k
Closed
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
fn main() { println!("Hello, {}!", crate::bar::do_the_thing); } pub mod foo { pub mod bar { pub fn do_the_thing() -> usize { 42 } } }
Current output
error[E0433]: failed to resolve: unresolved import --> src/main.rs:4:35 | 4 | println!("Hello, {}!", crate::bar::do_the_thing); | ^^^ unresolved import | help: a similar path exists | 4 | println!("Hello, {}!", crate::crate::foo::bar::do_the_thing); | ~~~~~~~~~~~~~~~ help: consider importing this module | 1 + use crate::foo::bar; | help: if you import `bar`, refer to it directly | 4 - println!("Hello, {}!", crate::bar::do_the_thing); 4 + println!("Hello, {}!", bar::do_the_thing);
Desired output
error[E0433]: failed to resolve: unresolved import --> src/main.rs:4:35 | 4 | println!("Hello, {}!", crate::bar::do_the_thing); | ^^^ unresolved import | help: a similar path exists | 4 | println!("Hello, {}!", crate::foo::bar::do_the_thing); | ~~~~~~~~ help: consider importing this module | 1 + use crate::foo::bar; | help: if you import `bar`, refer to it directly | 4 - println!("Hello, {}!", crate::bar::do_the_thing); 4 + println!("Hello, {}!", bar::do_the_thing);
Rationale and extra context
just a minor formatting logic bug I think. If a module name is missing in the middle of a chain (here crate::bar::do_the_thing
is used, but crate::foo::bar::do_the_thing
is defined) the suggestion is the full path, not just the bit in the middle that is missing.
Other cases
you need 2 nested modules for this problem to show up. Just one nested module works fine.
Rust Version
rustc 1.75.0 (82e1608df 2023-12-21) binary: rustc commit-hash: 82e1608dfa6e0b5569232559e3d385fea5a93112 commit-date: 2023-12-21 host: x86_64-unknown-linux-gnu release: 1.75.0 LLVM version: 17.0.6
Anything else?
No response
Metadata
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.