You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fnfoo(a:bool,b:bool) -> Option<bool>{if a {Some(b)}elseif b {// Some commentary about why this branch is important etc.None}elseif !a {// Some more commentary about why this branch matters.None}else{Some(a)}}
I expected to see this happen: no false positives!
Instead, this happened: if_same_then_else deny-by-default lint fired. While, yes, the branches are indeed "duplicate" at a logical level, they are not at a syntactic level. In this particular case the code ended up this way because it was important to document why we’re returning None if b and then None if !a, These comments could be rewritten to somehow combine them together, but there's probably nothing that’s clearer than just splitting code into a couple of the else if branches seen above.
This is not a false positive. The lint is designed so. If you consider having a separate branch more important here than applying the lint suggestion, you can annotate the fn definiction with #[allow(clippy::if_same_then_else)].
I tried this code:
I expected to see this happen: no false positives!
Instead, this happened:
if_same_then_else
deny-by-default lint fired. While, yes, the branches are indeed "duplicate" at a logical level, they are not at a syntactic level. In this particular case the code ended up this way because it was important to document why we’re returningNone if b
and thenNone if !a
, These comments could be rewritten to somehow combine them together, but there's probably nothing that’s clearer than just splitting code into a couple of theelse if
branches seen above.Meta
cargo clippy -V
: clippy 0.0.212 (de521cb 2020-08-21)rustc -Vv
: rustc 1.47.0-nightly (de521cb 2020-08-21)(Knowing compilers, this is probably not super actionable, feel free to close if you aren’t too keen on adjusting behaviour here)
The text was updated successfully, but these errors were encountered: