Confusing error message with derived Traits #41825
Labels
A-diagnostics
Area: Messages for errors, warnings, and lints
C-enhancement
Category: An issue proposing an enhancement or a PR with one.
D-confusing
Diagnostics: Confusing error or lint that should be reworked.
D-newcomer-roadblock
Diagnostics: Confusing error or lint; hard to understand for new users.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
I was trying to drain a referenced HashSet into a Vec to sort it before another operation,
but when I tried to clone the HashSet so that I could mutate it, this error appeared.
After cloning the HashSet I assumed that I should be able to use it in a moved, mutable context, so I tried to foce the type of the variable in the declaration, which gave me this error:
The issue with the borrowing for cloning and reference vs non-reference in the return type of the clone() threw me off the track. Eventually, the solution I found was that I'd forgotten to derive Clone on the enum called DayOfWeek that the HashSet works over, and adding that derivation fixed the problem. The error message seems misleading because I thought I had referencing error somewhere, and the error message didn't reference a Clone trait at all, but the problem only had to do with the derivation.
An example set up could look like this:
And this will compile only if the Day enum derives Clone.
Rust version:
The text was updated successfully, but these errors were encountered: