cmp
on non-Ord
type says problem is type doesn't implement Iterator
#113550
Labels
A-diagnostics
Area: Messages for errors, warnings, and lints
D-confusing
Diagnostics: Confusing error or lint that should be reworked.
D-incorrect
Diagnostics: A diagnostic that is giving misleading or incorrect information.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
Code
playground
Current output
Desired output
I would like the output to recommend implementing or deriving
Ord
to getcmp
instead of saying "the traitIterator
must be implemented", as implementingOrd
is much more likely to be what I'm trying to do (in my experience).Rationale and extra context
I tried calling
cmp
on a custom type that I had forgotten to deriveOrd
on, and I was surprised to see the compiler tell me the problem was that I didn't implementIterator
(which also has acmp
method, but isn't the best/most likely trait to providecmp
in this case).Other cases
Interestingly, if I call
sort_by
a vec ofOopsNoOrd
s such that I'm callingcmp
on&OopsNoOrd
instead ofOopsNoOrd
, then the compiler says I need bothOrd
andIterator
. This code:gives me:
Anything else?
I'm using rustc 1.70.0, and I'm seeing the same compiler output with beta 1.71.0-beta.6 and nightly 2023-07-09 1065d87.
The text was updated successfully, but these errors were encountered: