rust-lang / rust-lang/rust

Missing impl Trait parameter diagnostic is misleading

Open
#139,676 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Code
pub trait Foo {
    fn foo(d: impl std::fmt::Debug);
}

impl Foo for i32 {
    fn foo() {}
}
Current output
error[E0049]: associated function `foo` has 0 type parameters but its trait declaration has 1 type parameter
 --> src/lib.rs:6:11
  |
2 |     fn foo(d: impl std::fmt::Debug);
  |               --------------------
  |               |
  |               expected 1 type parameter
  |               `impl Trait` introduces an implicit type parameter
...
6 |     fn foo() {}
  |           ^ found 0 type parameters

For more information about this error, try `rustc --explain E0049`.
Desired output
error[E0049]: method `foo` has 0 parameters but its trait declaration has 1 parameter
 --> src/lib.rs:6:11
  |
2 |     fn foo(d: impl std::fmt::Debug);
  |            -----------------------
  |            |
  |            expected 1 parameter
...
6 |     fn foo() {}
  |           ^ found 0 parameters

For more information about this error, try `rustc --explain E0049`.
Rationale and extra context

Although it's not wrong that there is a type parameter mismatch (and it calls out that impl Trait creates an implicit type parameter), I think the more obvious error is that the number of parameters doesn't match.

Cross-crate, the impl Trait hint isn't present, so the error becomes more confusing.

Other cases

Rust Version
rustc --version --verbose
rustc 1.88.0-nightly (0fe8f3454 2025-04-10)
binary: rustc
commit-hash: 0fe8f3454dbe9dda52a254991347e96bec579a6f
commit-date: 2025-04-10
host: aarch64-apple-darwin
release: 1.88.0-nightly
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 example in src/lib.rs with the reported nightly rustc version and read the E0049 diagnostic, including rustc --explain E0049. Trace the compiler diagnostic entry point for this mismatch and adjust the result so a missing impl method parameter is reported as a parameter-count error; done when the output matches the desired wording without losing relevant diagnostics.

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
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.