Is it a misleading error message E0790 with Default::default()

fn main() {
   let i = Default::default();
   println!("i = {}", i); // i = 0
}

As-Is:

error[E0790]: cannot call associated function on trait without specifying the corresponding `impl` type
 --> src/main.rs:2:13
  |
2 |     let i = Default::default();
  |             ^^^^^^^^^^^^^^^^^^ cannot call associated function of trait
  |
help: use a fully-qualified path to a specific available implementation
  |
2 |     let i = </* self type */ as Default>::default();
  |             +++++++++++++++++++        +

Should-Be:
I am expecting error message something along the lines "explicit type expected / provide type information for variable i".

1 Like

I think this part could be reworded:

cannot call associated function on trait without specifying the corresponding impl type

Because you certainly can do that if the type can be inferred (it just couldn't be inferred in this case).

1 Like

Very much a "technically correct" message, I've grown a bit blind to how confusing it actually is. I understand that bug reports for error messages are generally well received, if nobody here beats you to it.

It might also be worth suggesting /* explicit type */::default() instead since Default is in scope (and presumably the explicit type doesn't have an inherent default method), that feels a bit more idiomatic to me, but perhaps a few too many caveats there.