-
Notifications
You must be signed in to change notification settings - Fork 1.8k
[FP] identity_op in front of if #8730
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -77,4 +77,34 @@ fn main() { | |
(x + 1) % 3; // no error | ||
4 % 3; // no error | ||
4 % -3; // no error | ||
|
||
// See #8724 | ||
let a = 0; | ||
let b = true; | ||
0 + if b { 1 } else { 2 }; | ||
0 + if b { 1 } else { 2 } + if b { 3 } else { 4 }; // no error | ||
0 + match a { 0 => 10, _ => 20 }; | ||
0 + match a { 0 => 10, _ => 20 } + match a { 0 => 30, _ => 40 }; // no error | ||
0 + if b { 1 } else { 2 } + match a { 0 => 30, _ => 40 }; // no error | ||
0 + match a { 0 => 10, _ => 20 } + if b { 3 } else { 4 }; // no error | ||
|
||
0 + if b { 0 + 1 } else { 2 }; | ||
0 + match a { 0 => 0 + 10, _ => 20 }; | ||
0 + if b { 0 + 1 } else { 2 } + match a { 0 => 0 + 30, _ => 40 }; | ||
|
||
let _ = 0 + if 0 + 1 > 0 { 1 } else { 2 } + if 0 + 1 > 0 { 3 } else { 4 }; | ||
let _ = 0 + match 0 + 1 { 0 => 10, _ => 20 } + match 0 + 1 { 0 => 30, _ => 40 }; | ||
Comment on lines
+95
to
+96
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's a false negative in here, in contexts where it's unambiguously an expression it is fine to reduce these, e.g. let b = true;
f(0 + if b { 1 } else { 2 } + 3);
let _ = 0 + if b { 1 } else { 2 } + 3;
const _: i32 = 0 + if b { 1 } else { 2 } + 3; Perhaps instead of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Those cases don't lint currently but they could do is what I mean, as in // doesn't trigger the lint
f(0 + if b { 1 } else { 2 } + 3);
// but it could, as the following is valid
f(if b { 1 } else { 2 } + 3); It'd be also fine to leave it as is and make a note of that under a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I didn't aware of this case. I will leave it as it is and add documents. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added documents |
||
|
||
0 + if b { 1 } else { 2 } + if b { 3 } else { 4 } + 0; | ||
|
||
0 + { a } + 3; // no error | ||
0 + loop { let mut c = 0; if c == 10 { break c; } c += 1; } + { a * 2 }; // no error | ||
|
||
fn f(_: i32) { | ||
todo!(); | ||
} | ||
f(1 * a + { 8 * 5 }); | ||
f(0 + if b { 1 } else { 2 } + 3); // no error | ||
const _: i32 = { 2 * 4 } + 0 + 3; | ||
const _: i32 = 0 + { 1 + 2 * 3 } + 3; // no error | ||
} |
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.
I would like to see a testcase like
let _c = 0 + if b { 1 } else { 2 };
Maybe also a function like I wrote in #8724: