Cast error doesn't suggest boxed traits but maybe it should.

b640c4f
Opened by Ram at 2024-08-29 23:30:50

I have a function call that's something like:

test(&[&"nani?" as &_, &"=_=".to_owned() as &_]);

The first &_ is interpreted as a no-op cast, and the second is interpreted as a &String -> &&str. I did this to try and get a list of boxed traits, but the error message is pretty misleading unless you notice what the compiler's actually inferring, and almost makes it sound like as can't be used in this situation at all:

error[E0605]: non-primitive cast: `&std::string::String` as `&&str`
...
  = note: an `as` expression can only be used to convert between primitive types. Consider using the `From` trait

I don't know how, but it would be nice if it could automagically recommend boxed traits in similar situations.

Playground