Skip to content

Friendlier compiler message for incorrect trait method signatures #28011

Closed
@andersforsgren

Description

@andersforsgren

When implementing a trait, it would be useful to see the expected method signature in compiler error messages. Example

impl std::fmt::Display for MyType {
   // Not sure what to put here so I stub it and hope to get help from error
   fn fmt() -> () { } 
}   

The current error message for E0186 only lets me partially resolve the issue:

error: method `fmt` has a `&self` declaration in the trait, but not in the impl [E0186]

It would be more friendly to the user if the message showed both the actual and expected method signatures.

Incorrect method signature for trait `Display` method `fmt`
Actual signature    fn fmt() -> ()
Expected signature  fn fmt(&self, &mut Formatter) -> Result<(), Error>

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lints

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions