Improve error messages for HashSet with non-Hash type #87015
Labels
A-diagnostics
Area: Messages for errors, warnings, and lints
C-bug
Category: This is a bug.
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 ran into a situation with confusing error messages constructing a
HashSet
with a type that doesn't inheritHash
.I tried this code:
I expected to see this happen:
The values from
value.uses
to be inserted into the setlive_in
. Or, an error message letting me know what's wrong.Instead, this happened:
I saw the following error:
This error message isn't terribly helpful. It was especially confusing because I had called
extend
on other sets without incident. After searching for a while to figure out what was going wrong, I decided to just try manually inserting the values:This time, I received a considerably more helpful error message:
Ultimately, the problem was I neglected to implement
Hash
for myTemp
type. That's obviously a straightforward user error, but also one that I think is reasonably common. The reason I'm filing an issue is I think the error messages could be improved here to help out users better. I suppose what's most surprising to me is that the following line didn't error:I would have expected the bounds check to happen as the type was being constructed, rather than delaying it until an operation on the value. There's likely some reason to allow construction of
HashSet
with a non-Hash
type, but the interaction leads to errors that I think are a bit removed from the source.Meta
rustc --version --verbose
:The text was updated successfully, but these errors were encountered: