-
-
Notifications
You must be signed in to change notification settings - Fork 14.9k
Suggest using equality comparison instead of pattern matching on non-structural constant in pattern #154010
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Suggest using equality comparison instead of pattern matching on non-structural constant in pattern #154010
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,6 +11,11 @@ LL | BAR_BAZ => panic!(), | |
| | ^^^^^^^ constant of non-structural type | ||
| | | ||
| = note: see https://doc.rust-lang.org/stable/std/marker/trait.StructuralPartialEq.html for details | ||
| help: add a condition to the match arm checking for equality | ||
| | | ||
| LL - BAR_BAZ => panic!(), | ||
| LL + binding if binding == BAR_BAZ => panic!(), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's a bit confusing that the error message suggests two separate ways of fixing this -- add
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, I was looking on how to address this. I'll follow up. |
||
| | | ||
|
|
||
| error: aborting due to 1 previous error | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This non-local case is tricky, because the other crate might be under the author's control and able to be changed. I guess it's impossible to know for sure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was going back and forth on this one. I settled on "we're giving them a link to the docs". I was concerned with giving the impression to the user that they had to somehow fork their dep. We could instead say something like "
CustomEqcould be used in patterns if it was annotated with#[derive(PartialEq)]", but I fear that has the same problem.