Description
Type mismatch error could be more specific and friendlier if it had special handling of case where the compiler found &type
, but expected type
.
error: mismatched types [--explain E0308]
…
^ expected enumstd::option::Option
, found &-ptr
The current message is correct and (with notes) it's possible to understand it, but "expected type
, found &-ptr" obscures what type has actually been found (#25426), and makes it sound like a worse mismatch than it really is.
note: expected type
std::option::Option<_>
note: found type&std::option::Option<foo>
Notes for this error make the problem clear, but they're repeating the first part of the message, so it's already using four lines to say one thing. Listing both types requires me to compare them and spot the difference myself.
I hope there are no weird edge cases in this situation, and the compiler could simplify the message by proposing solution outright. Something like:
error: value must be dereferenced
Expectedstd::option::Option<_>
. Use*var
instead ofvar
to dereference&std::option::Option<foo>
.