-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
if x { true } else { false } #12
Comments
I think that one should be simple enough to detect, and it's also easy to create a good warning. I'd catch all instances of if { Lit:bool } else { Lit:bool } and suggest a suitable replacement based on the literals. I'll take a stab at it when I find some free time. |
Yep, it's pretty simple. Go ahead! :) |
It'd be great to have a general, declarative way to express rules like that. Maybe something similar to Coccinelle. |
Technically it's just a single huge match statement (assuming |
It would be cool to do this with quotation: fn check_expr(&mut self, cx: &Context, expr: &Expr) {
match *expr {
q!(if $e:expr { $a:lit } else { $b:lit }) => ... I think this is actually achievable now, if you replace the whole |
A macro should be able to generate code to deal with |
Done. The warnings could give more specific directions (they are a bit abstract for a newbie), but it works, and it's late now; I guess, I'll revisit them later. |
Not a Rust-specific problem but I've seen it a lot in code from people who are new to programming in general.
Could generalize to find other forms that are better expressed by logical operators.
The text was updated successfully, but these errors were encountered: