Fixed branches_sharing_code FP with block expressions in else

And added `branches_sharing_code` PF note to lint doc for `rust-clippy#7452`
This commit is contained in:
xFrednet 2021-07-13 23:27:19 +02:00
parent 8131445e53
commit 61e280863f
2 changed files with 33 additions and 3 deletions

View file

@ -120,7 +120,10 @@ declare_clippy_lint! {
///
/// **Why is this bad?** Duplicate code is less maintainable.
///
/// **Known problems:** Hopefully none.
/// **Known problems:**
/// * The lint doesn't check if the moved expressions modify values that are beeing used in
/// the if condition. The suggestion can in that case modify the behavior of the program.
/// See [rust-clippy#7452](https://github.com/rust-lang/rust-clippy/issues/7452)
///
/// **Example:**
/// ```ignore
@ -358,8 +361,7 @@ fn scan_block_for_eq(cx: &LateContext<'tcx>, blocks: &[&Block<'tcx>]) -> Option<
expr_eq &= block_expr_eq;
}
let has_expr = blocks[0].expr.is_some();
if has_expr && !expr_eq {
if !expr_eq {
end_eq = 0;
}

View file

@ -0,0 +1,28 @@
#![allow(dead_code)]
#![deny(clippy::if_same_then_else, clippy::branches_sharing_code)]
// ##################################
// # Issue clippy#7369
// ##################################
#[derive(Debug)]
pub struct FooBar {
foo: Vec<u32>,
}
impl FooBar {
pub fn bar(&mut self) {
if true {
self.foo.pop();
} else {
self.baz();
self.foo.pop();
self.baz()
}
}
fn baz(&mut self) {}
}
fn main() {}