When using the crate name as a path instead of crate:: rustc should probably suggest using crate:: instead
Open
Nobody has claimed this yet.
A-diagnostics
D-lack-of-suggestion
T-compiler
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
Code
When in a crate that has a library and a binary symbols used fully qualified need to have the crate name at the start of the path in the binary but crate:: in the library so when moving code around you can run into errors complaining about an undeclared crate or module <current crate name>.
Not only should rustc probably notice that this is the current crate name and point that out in the error message, it should also likely suggest crate:: as a replacement.
It probably also couldn't hurt to figure out that the fully qualified path refers to the current module and suggest removal of the path entirely.
Current output
error[E0433]: failed to resolve: use of undeclared crate or module `salt_update_gitlab_keys`
--> src/types.rs:88:40
|
88 | let deploy_keys: std::vec::Vec<salt_update_gitlab_keys::types::SSHPublicKey> = deploy_keys
| ^^^^^^^^^^^^^^^^^^^^^^^ use of undeclared crate or module `salt_update_gitlab_keys`
Desired output
error[E0433]: failed to resolve: use of undeclared crate or module `salt_update_gitlab_keys`
--> src/types.rs:88:40
|
88 | let deploy_keys: std::vec::Vec<salt_update_gitlab_keys::types::SSHPublicKey> = deploy_keys
| ^^^^^^^^^^^^^^^^^^^^^^^ use of undeclared crate or module `salt_update_gitlab_keys`
|
help: the current crate name can not be used in a path in a library module, use the literal text crate instead
|
help: the fully qualified path for this symbol refers to the current module, you might want to remove the path completely
Rationale and extra context
Ran into the current ouput above while splitting up the previously only binary module into several modules in my (private) crate salt_update_gitlab_keys and moving code around from src/bin/salt_update_gitlab_keys.rs to src/types.rs
Other cases
Rust Version
rustc 1.85.0 (4d91de4e4 2025-02-17)
binary: rustc
commit-hash: 4d91de4e48198da2e33413efdcd9cd2cc0c46688
commit-date: 2025-02-17
host: x86_64-unknown-linux-gnu
release: 1.85.0
LLVM version: 19.1.7
Anything else?
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the E0433 example with a library and binary, then trace rustc's E0433 diagnostic handling for paths using the current crate name. Done means the relevant library-module case explains that crate:: should be used and offers the requested replacement or path-removal suggestion, with coverage for the demonstrated behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100