-
-
Notifications
You must be signed in to change notification settings - Fork 78
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
feat: add trait_associated_const_default_removed lint #888
feat: add trait_associated_const_default_removed lint #888
Conversation
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.
The query is very close! I've added an explanation for what is going wrong and why, hopefully that makes the problem clear.
Thanks for putting this together!
associated_constant @fold @transform(op: "count") @filter(op: "=", value: ["$zero"]) { | ||
name @filter(op: "=", value: ["%associated_constant"]) | ||
default @filter(op: "is_not_null") | ||
} |
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 clause says: "there are no associated constants such that both the name matches and there is a default value." So not having any associated constant at all is a match, as is having only constants with different names, or only having constants without default values.
We want something different: "there exists an associated constant with a matching name and with a default value." This way, not having the right constant name is not a match, and not having a default value is not a match.
The clause we want is actually the inverted version of what the query currently says. The query says "there does not exist" but we actually do want it to exist. Merely removing the "there does not exist" part of the query (the "count is zero" part) is sufficient to fix it:
associated_constant @fold @transform(op: "count") @filter(op: "=", value: ["$zero"]) { | |
name @filter(op: "=", value: ["%associated_constant"]) | |
default @filter(op: "is_not_null") | |
} | |
associated_constant { | |
name @filter(op: "=", value: ["%associated_constant"]) | |
default @filter(op: "is_not_null") | |
} |
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.
Excellent! 🚀
Did my explanation of the query change make sense btw? Happy to answer any further questions you may have! |
The explanation makes perfect sense once you have it, but to reach this myself, I think I need a bit more practice with |
Of course, makes sense. Happy to support you as you practice. Btw I just made a Discord server for cargo-semver-checks and Trustfall, to make coordination a bit easier. You're welcome to join if you'd like — there are many other people in similar places in their learning journey there: https://discord.gg/s7Cfmp3P |
Lint for "non-sealed trait removed the default value for an associated constant"
See #870
I still haven't fully made myself of a mental model of how to create queries. Here's a starting point. The query I made matches another test with incoherent results.