Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When using the crate name as a path instead of crate:: rustc should probably suggest using crate:: instead #138312

Open
taladar opened this issue Mar 10, 2025 · 0 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@taladar
Copy link

taladar commented Mar 10, 2025

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

@taladar taladar added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Mar 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

1 participant