Skip to content

E0050 emitted unexpectedly on missing : #129273

Open

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-parserArea: The parsing of Rust source code to an ASTD-confusingDiagnostics: Confusing error or lint that should be reworked.D-papercutDiagnostics: An error or lint that needs small tweaks.D-verboseDiagnostics: Too much output caused by a single piece of incorrect code.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions