rust-lang / rust-lang/rust

E0050 emitted unexpectedly on missing `:`

Open
#129,273 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Code
use std::fmt;

struct Hello;

impl fmt::Display for Hello {
    fn fmt(&self, f: &fmt:Formatter) -> fmt::Result {
        write!(f, "hello")
    }
}
Current output
Compiling playground v0.0.1 (/playground)
error: expected parameter name, found `:`
 --> src/lib.rs:6:26
  |
6 |     fn fmt(&self, f: &fmt:Formatter) -> fmt::Result {
  |                          ^ expected parameter name

error: expected one of `!`, `(`, `)`, `,`, `::`, or `<`, found `:`
 --> src/lib.rs:6:26
  |
6 |     fn fmt(&self, f: &fmt:Formatter) -> fmt::Result {
  |                          ^
  |                          |
  |                          expected one of `!`, `(`, `)`, `,`, `::`, or `<`
  |                          help: missing `,`

error[E0573]: expected type, found module `fmt`
 --> src/lib.rs:6:23
  |
6 |     fn fmt(&self, f: &fmt:Formatter) -> fmt::Result {
  |                       ^^^ not a type

error[E0050]: method `fmt` has 3 parameters but the declaration in trait `std::fmt::Display::fmt` has 2
 --> src/lib.rs:6:12
  |
6 |     fn fmt(&self, f: &fmt:Formatter) -> fmt::Result {
  |            ^^^^^^^^^^^^^^^^^^^^^^^^ expected 2 parameters, found 3
  |
  = note: `fmt` from trait: `fn(&Self, &mut Formatter<'_>) -> Result<(), std::fmt::Error>`

Some errors have detailed explanations: E0050, E0573.
For more information about an error, try `rustc --explain E0050`.
error: could not compile `playground` (lib) due to 4 previous errors
Desired output
Compiling playground v0.0.1 (/playground)
error: expected parameter name, found `:`
 --> src/lib.rs:6:26
  |
6 |     fn fmt(&self, f: &fmt:Formatter) -> fmt::Result {
  |                          ^ expected parameter name

error: expected one of `!`, `(`, `)`, `,`, `::`, or `<`, found `:`
 --> src/lib.rs:6:26
  |
6 |     fn fmt(&self, f: &fmt:Formatter) -> fmt::Result {
  |                          ^
  |                          |
  |                          expected one of `!`, `(`, `)`, `,`, `::`, or `<`
  |                          help: missing `,`

error[E0573]: expected type, found module `fmt`
 --> src/lib.rs:6:23
  |
6 |     fn fmt(&self, f: &fmt:Formatter) -> fmt::Result {
  |                       ^^^ not a type

Some errors have detailed explanations: E0050, E0573.
For more information about an error, try `rustc --explain E0050`.
error: could not compile `playground` (lib) due to 4 previous errors
Rationale and extra context

When looking at rust-analyzer output or when just looking at the last few error messages, it's easy to see only the "too many arguments" error, and not the syntax error that points at the exact problem.

Other cases

No response

Rust Version
1.80.1
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 Rust 1.80.1 diagnostic with the issue's malformed fmt parameter and compare the current and desired outputs. Trace the compiler's handling of the parse error and trait method arity check; done means the syntax and type errors remain while the spurious E0050 diagnostic is omitted.

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.