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

short diagnostic for E0432 incorrectly describes the problem #133137

Closed
workingjubilee opened this issue Nov 17, 2024 · 0 comments · Fixed by #133154
Closed

short diagnostic for E0432 incorrectly describes the problem #133137

workingjubilee opened this issue Nov 17, 2024 · 0 comments · Fixed by #133154
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints D-confusing Diagnostics: Confusing error or lint that should be reworked. D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. D-terse Diagnostics: An error or lint that doesn't give enough information about the problem at hand. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@workingjubilee
Copy link
Member

workingjubilee commented Nov 17, 2024

Code

use some_novel_crate::Type;

fn main() {
    println!("{}", Type::new());
}

Current output

Compiling playground v0.0.1 (/playground)
error[E0432]: unresolved import `some_novel_crate`
 --> src/main.rs:1:5
  |
1 | use some_novel_crate::Type;
  |     ^^^^^^^^^^^^^^^^ use of undeclared crate or module `some_novel_crate`

For more information about this error, try `rustc --explain E0432`.
error: could not compile `playground` (bin "playground") due to 1 previous error

Desired output

Compiling playground v0.0.1 (/playground)
error[E0432]: unresolved import `some_novel_crate`
  --> src/main.rs:1:5
   |
 1 | use some_novel_crate::Type;
-   |     ^^^^^^^^^^^^^^^^ use of undeclared crate or module `some_novel_crate` 
+   |     ^^^^^^^^^^^^^^^^ use of unresolved module or unlinked crate `some_novel_crate` 

 For more information about this error, try `rustc --explain E0432`.
+help: Consider using `cargo add some_novel_crate` to add the crate to your Cargo.toml
+help: Consider defining a module: `mod some_novel_crate { }`
 error: could not compile `playground` (bin "playground") due to 1 previous error

Rationale and extra context

playground: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=a60453f1bdbe2f05f3e1d05560f189f5

If we want people to actually learn the language's finer points, we need to be careful to not casually hack apart the mental model by misusing our own terminology. There is clearly a declaration right there, so saying it is undeclared is misleading at best, actively harmful to understanding at worst: https://doc.rust-lang.org/reference/items/use-declarations.html

Further, a resolution error failing to turn up a module is solved in a very different way, from a user perspective, from a crate not being resolved.

Other cases

Rust Version

rustc 1.84.0-nightly (f2a35426b 2024-11-16)
binary: rustc
commit-hash: f2a35426b6586178c44b27cedae182502092e898
commit-date: 2024-11-16
host: x86_64-unknown-linux-gnu
release: 1.84.0-nightly
LLVM version: 19.1.3

Anything else?

No response

@workingjubilee workingjubilee 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. D-confusing Diagnostics: Confusing error or lint that should be reworked. D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. D-terse Diagnostics: An error or lint that doesn't give enough information about the problem at hand. labels Nov 17, 2024
@estebank estebank self-assigned this Nov 18, 2024
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jan 22, 2025
Reword resolve errors caused by likely missing crate in dep tree

Reword label and add `help`:

```
error[E0432]: unresolved import `some_novel_crate`
 --> f704.rs:1:5
  |
1 | use some_novel_crate::Type;
  |     ^^^^^^^^^^^^^^^^ use of unresolved module or unlinked crate `some_novel_crate`
  |
  = help: if you wanted to use a crate named `some_novel_crate`, use `cargo add some_novel_crate` to add it to your `Cargo.toml`
```

Fix rust-lang#133137.
jhpratt added a commit to jhpratt/rust that referenced this issue Jan 23, 2025
Reword resolve errors caused by likely missing crate in dep tree

Reword label and add `help`:

```
error[E0432]: unresolved import `some_novel_crate`
 --> f704.rs:1:5
  |
1 | use some_novel_crate::Type;
  |     ^^^^^^^^^^^^^^^^ use of unresolved module or unlinked crate `some_novel_crate`
  |
  = help: if you wanted to use a crate named `some_novel_crate`, use `cargo add some_novel_crate` to add it to your `Cargo.toml`
```

Fix rust-lang#133137.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jan 23, 2025
Reword resolve errors caused by likely missing crate in dep tree

Reword label and add `help`:

```
error[E0432]: unresolved import `some_novel_crate`
 --> f704.rs:1:5
  |
1 | use some_novel_crate::Type;
  |     ^^^^^^^^^^^^^^^^ use of unresolved module or unlinked crate `some_novel_crate`
  |
  = help: if you wanted to use a crate named `some_novel_crate`, use `cargo add some_novel_crate` to add it to your `Cargo.toml`
```

Fix rust-lang#133137.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jan 25, 2025
Reword resolve errors caused by likely missing crate in dep tree

Reword label and add `help`:

```
error[E0432]: unresolved import `some_novel_crate`
 --> f704.rs:1:5
  |
1 | use some_novel_crate::Type;
  |     ^^^^^^^^^^^^^^^^ use of unresolved module or unlinked crate `some_novel_crate`
  |
  = help: if you wanted to use a crate named `some_novel_crate`, use `cargo add some_novel_crate` to add it to your `Cargo.toml`
```

Fix rust-lang#133137.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jan 25, 2025
Reword resolve errors caused by likely missing crate in dep tree

Reword label and add `help`:

```
error[E0432]: unresolved import `some_novel_crate`
 --> f704.rs:1:5
  |
1 | use some_novel_crate::Type;
  |     ^^^^^^^^^^^^^^^^ use of unresolved module or unlinked crate `some_novel_crate`
  |
  = help: if you wanted to use a crate named `some_novel_crate`, use `cargo add some_novel_crate` to add it to your `Cargo.toml`
```

Fix rust-lang#133137.
@bors bors closed this as completed in 203e6c1 Jan 25, 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 D-confusing Diagnostics: Confusing error or lint that should be reworked. D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. D-terse Diagnostics: An error or lint that doesn't give enough information about the problem at hand. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants