-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Lint: comparing two expressions of unit type #4481
Comments
unit_cmp already checks for comparisons. It can be extended to work with I wonder if we could lint any expression that contains a call to function that returns |
We explicitly exclude expanded code from that lint: rust-clippy/clippy_lints/src/types.rs Lines 529 to 531 in a3fcaee
I'm not sure if that is necessary, since even when |
I could imagine a more complicated macro that is general to a lot of types and does a comparison somewhere without being incorrect. Is there any precedent for doing some sort of heuristic as to how complex the macro is and therefore how likely it is that its sole purpose is the comparison? |
We can't look into the macro, we only can check the expanded code, so there is no way to know the complexity of a macro. I would change this lint, to not trigger on external_macros, but exclude assert_eq! from this. |
@flip1995, and perhaps the whole family: |
@flip1995 Commenting out rust-clippy/clippy_lints/src/types.rs Lines 529 to 531 in a3fcaee
will still generate warnings when deriving e.g. PartialEq. And according to the comment in the rust-clippy/tests/ui/unit_cmp.rs Lines 4 to 5 in 737f0a6
So I think that check is still needed. But I was digging around and I think I found a way to implement special exceptions for asserts using I would like to work on this issue if there isn't already someone working on it. |
I recently wrote a test like this
but much to my surprise, the test kept passing even if I changed the literal
at this point I realized that what I wrote was as good as this useless comparison
In order to catch people who try to do things like this, I suggest that we lint comparing two expressions of unit type, since the result will always be true and it would be more straightforward just to write two lines for each expression e.g.
In addition to the canonical Unit Type
()
, I suggest that we lint for expressions of any user-created unit type such as:Thoughts?
The text was updated successfully, but these errors were encountered: