rust-lang / rust-lang/rust

rustc confuses missing types with missing type parameters

Open
#139,999 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-diagnostics A-resolve D-papercut T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the diagnostic from the src/lib.rs example using rustc 1.86.0 and compare the current output with the requested output. Review the compiler diagnostic path that proposes a missing type parameter, then determine which agreed rule should suppress the suggestion for this case. Done means the unwanted help text is absent while valid missing-type-parameter suggestions remain covered by tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.