-
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
RFC: Warning on tautology in if or while statements #2087
Conversation
Note that in general we might want functions to be able to allow this for expressions containing them. If you have a function that on architecture X does some work, and on architecture Y always returns a constant value, you shouldn't get a warning on architecture Y. |
This is why there is an |
Agree with @joshtriplett . The lint has too many false positives. You shouldn't have to regularly |
Why would it have a lot of false positives, is the current checker that positived-biased? |
AFAIK there is no current checker. The check for That's why your RFC as written requires (to my knowledge) an entirely new checker to be implemented (and it's quite underspecified in that regard, probably because you did not realize this). |
That is quite true that I did not realize that it did not exist. I will add those sorts of requirements to the RFC |
This is probably better in Clippy than the compiler (I think if the |
@nrc I'd be very surprised if clippy doesn't already have this including a check that it came from a macro (so |
Clippy has http://rust-lang-nursery.github.io/rust-clippy/master/#nonminimal_bool and http://rust-lang-nursery.github.io/rust-clippy/master/#logic_bug which deal with collapsing conditions. Neither does it actually warn if you do Both of these lints could be added. |
I wasn't arguing against this; I was arguing for implementing it with care to make sure it doesn't trigger on things that depend on cfg or similar conditional compilation. |
Another benefit for something like this would be moving towards logical proofs of conditions |
@Manishearth Are you saying that those lints could be added to rustc or clippy, it seems to me that you are saying that if they were in rustc the information is already there |
@Nokel81 There shouldn't be any difference between |
Closing so that this can be discussed as an addition to clippy |
This is the initial commit for the RFC that adds compiler warnings for tautologies and contradictions. Similar to how there is currently a warning for
while true { }
Edit: Rendered