-
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
immutable while condition lint should not trigger on constants #2514
Comments
Ooops! I initially had a "has_var" check that I must have removed while moving code to "visitor". But what would be the usecase for |
@kimsnj I'm not 100% sure on what we should be doing here. Because you are catching let x = false;
while x {} Which is absolutely correct, the condition is useless because it cannot change, but maybe the user meant to iterate if some condition is met, but not otherwise, and the loop will terminate by other means. "Cleaner" would be I don't really know how to move forward from here. |
@oli-obk We could push the reasoning a bit further… let x = 5;
while x > 1 {} Should the above snippet be caught or not? Maybe we could split the lint in 2 diffrent ones:
Not directly related to this (as it might actually impact both), what I find a bit lacking in this lint is that cases such as: let mut vec: Vec::new();
while vec.len() > 0 {
println!("Hello world");
} are note covered. |
That specific one results in
so I'm not worried. but I see your point. If we allowed immutable method/function calls and added a check for interior mutability then those cases should be covered, too. We don't need to be perfect, just without false positives ;) |
let x = 5;
while x > 1 {} should be linted, because The current lint message could be adjusted to |
Actually checking that the method only takes its argument immutably wouldn't be sufficient (e.g. generate a random number / reads from file …). Thus having some white-listed modules for which we do not directly bail. |
oh... right. we'd need purity... well... let's just stay with the obvious numeric cases. And yea, just throw the const evaluator on it. if it returns anything, don't lint. |
cc @kimsnj
currently
while false {}
triggers the lint,while SOME_CONST {}
would also trigger it, neither of them should. The condition should contain some local in order for the lint to trigger.The text was updated successfully, but these errors were encountered: