Skip to content

rustc confuses missing types with missing type parameters #139999

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

Open
Wilfred opened this issue Apr 18, 2025 · 1 comment
Open

rustc confuses missing types with missing type parameters #139999

Wilfred opened this issue Apr 18, 2025 · 1 comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-resolve Area: Name/path resolution done by `rustc_resolve` specifically D-papercut Diagnostics: An error or lint that needs small tweaks. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Wilfred
Copy link
Contributor

Wilfred commented Apr 18, 2025

Code

pub fn do_stuff() -> Option<ForgotToImport> {
    None
}

Current output

error[E0412]: cannot find type `ForgotToImport` in this scope
 --> src/lib.rs:1:29
  |
1 | pub fn do_stuff() -> Option<ForgotToImport> {
  |                             ^^^^^^^^^^^^^^ not found in this scope
  |
help: you might be missing a type parameter
  |
1 | pub fn do_stuff<ForgotToImport>() -> Option<ForgotToImport> {
  |                ++++++++++++++++

Desired output

error[E0412]: cannot find type `ForgotToImport` in this scope
 --> src/lib.rs:1:29
  |
1 | pub fn do_stuff() -> Option<ForgotToImport> {
  |                             ^^^^^^^^^^^^^^ not found in this scope

Rationale and extra context

Type parameters are rarely this long, so rustc's guess seems like a poor fit. Could rustc treat longer names as unlikely to be type parameters?

Another option would be to skip this suggestion if the type name is CamelCase.

Other cases

Rust Version

$ rustc --version --verbose
rustc 1.86.0 (05f9846f8 2025-03-31)
binary: rustc
commit-hash: 05f9846f893b09a1be1fc8560e33fc3c815cfecb
commit-date: 2025-03-31
host: x86_64-unknown-linux-gnu
release: 1.86.0
LLVM version: 19.1.7

Anything else?

No response

@Wilfred Wilfred 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 Apr 18, 2025
@fmease fmease changed the title rustc confuses missing types with type parameters rustc confuses missing types with missing type parameters Apr 18, 2025
@fmease fmease added A-resolve Area: Name/path resolution done by `rustc_resolve` specifically D-papercut Diagnostics: An error or lint that needs small tweaks. labels Apr 18, 2025
@Kivooeo
Copy link
Contributor

Kivooeo commented Apr 19, 2025

Hi, would love to take this one, almost finished writing implementation, and will add tests and so on tomorrow and publish it in PR

Kivooeo added a commit to Kivooeo/rust that referenced this issue Apr 20, 2025
Kivooeo added a commit to Kivooeo/rust that referenced this issue Apr 20, 2025
Kivooeo added a commit to Kivooeo/rust that referenced this issue Apr 20, 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 A-resolve Area: Name/path resolution done by `rustc_resolve` specifically D-papercut Diagnostics: An error or lint that needs small tweaks. 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

3 participants