Conversation
|
r? @giraffate (rust-highfive has picked a reviewer for you, use r? to override) |
bf3194e to
5761bb7
Compare
|
Use I think providing a code suggestion is important for this lint. The fix may not be intuitive and people may not be aware that |
5761bb7 to
0e5ccd7
Compare
0e5ccd7 to
9e85dc8
Compare
|
I'll leave it to @giraffate do to a full review. But note I still don't see the multi-line check. @Labelray don't hesitate to ask if something doesn't make sense! |
@camsteffen I didn't check the number of lines but I checked the number of statements. I think it is better. |
|
A long condition can be a single statement. if some_function(foo, bar, baz) == another_function(hi, whats, up)
&& some_function(a, b, c) == another_function(a, b, c) {
panic!();
} |
9e85dc8 to
73040c3
Compare
0d3c4f9 to
44ad749
Compare
giraffate
left a comment
There was a problem hiding this comment.
I made a comment but overall looks good, thanks!
tests/ui/fallible_impl_from.stderr
Outdated
| error: only a `panic!` in `if`-then statement | ||
| --> $DIR/fallible_impl_from.rs:28:9 | ||
| | | ||
| LL | / if i != 42 { | ||
| LL | | panic!(); | ||
| LL | | } | ||
| | |_________^ help: try: `assert!(!i != 42, "explicit panic");` | ||
| | | ||
| = note: `-D clippy::if-then-panic` implied by `-D warnings` | ||
|
|
There was a problem hiding this comment.
Can you add #![allow(clippy::if_then_panic)] and remove these warnings in this test file? It looks a little confusing.
There was a problem hiding this comment.
If this suggestion even valid?
!i != 42 is (!i) != 42 which is not what is intended to be suggested here. It should be !(i != 42).
Though, already reported: #7731
44ad749 to
5f750a8
Compare
giraffate
left a comment
There was a problem hiding this comment.
Can the conflict be resolved?
4807d0d to
5f750a8
Compare
|
We follow a no merge-commit policy. Can you do a rebase, not a merge? |
91d7588 to
1d8d337
Compare
1d8d337 to
543b638
Compare
|
@bors r+ Thanks! |
|
📌 Commit 543b638 has been approved by |
|
☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test |
Most of the changes are for the new if-then-panic lint added in rust-lang/rust-clippy#7669. Error messages look like: error: only a `panic!` in `if`-then statement --> zenith_utils/src/lsn.rs:195:9 | 195 | / if prev.checked_add(val).is_none() { 196 | | panic!("AtomicLsn overflow"); 197 | | } | |_________^ help: try: `assert!(!prev.checked_add(val).is_none(), "AtomicLsn overflow");` | = note: `-D clippy::if-then-panic` implied by `-D warnings` = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#if_then_panic
Most of the changes are for the new if-then-panic lint added in rust-lang/rust-clippy#7669.
|
@camsteffen @giraffate This issue causes regression: I would suggest reverting this lint or don't make it active by default (not sure if this is possible) |
|
This lint also transformed this code: to which... is weird. Why negate an integer? This also breaks my code since this assertion is now triggered, while the initial code wasn't being triggered. |
|
Hi @Jasperav, thanks for the feedback.
I don't think this is true, unless I misunderstood. See playground.
The lint is being moved to pedantic (off by default) in #7810.
This should be fixed from #7741. |
|
Edit: apparently, it can indeed catch assertions. Not sure what went wrong with my code. |
changelog: add the new lint [
if_then_panic]fix #7645