Anders Forsgren
Anders Forsgren

Reputation: 11101

Expected method signatures in trait error messages

I'm trying Rust and finding it hard to interpret what to do when my function signatures don't correspond to those expected by a trait. 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 compiler error message is

method `fmt` has a `&self` declaration in the trait, but not in the impl

What I was hoping to see was something helping me implement the method for example:

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

Is it possible to get signature help from the compiler like this? I'm usually very impressed by the very friendly and detailed compiler errors, so this one really surprised me. I'm using the rust playground (https://play.rust-lang.org/) but I don't think that makes any difference to compiler output.

Upvotes: 2

Views: 120

Answers (1)

Vladimir Matveev
Vladimir Matveev

Reputation: 127771

No, it is not possible. If you think this is an important feature, you can always submit a feature request to Rust issue tracker.

Meanwhile, you can use docs generated by rustdoc, e.g. these for the standard library. They are usually pretty awesome, especially given that there is search function.

Upvotes: 3

Related Questions