rust-clippy
rust-clippy copied to clipboard
improve [`almost_swapped`] to look for let statement
fix #8151
improve [almost_swapped
] to also detects code using let statements like
let b = 1;
let a = b;
let b = a;
let mut b = 1;
let a = b;
b = a;
changelog: improve [almost_swapped
] to look for code using let statement
r? @flip1995
(rust-highfive has picked a reviewer for you, use r? to override)
It would be better to rework this to parse the two statement into (Symbol|Expr, Expr)
pairs and then check if it's almost swapped. Something like:
fn parse(...) -> Option<(ExprOrLocal, Expr)> { ... }
if let Some((lhs0, rhs0)) = parse(stmt[0])
&& let Some((lhs1, rhs1)) = parse(stmt[1])
&& is_same(lhs0, rhs1)
&& is_same(lhs1, rhs0)
{ ... }
I like the suggestion by @Jarcho
. This makes the code more DRY. Can you refactor the code please?
Because I took too long for my review, I think this PR is stale, so I close it for now. @DevAccentor if you want to continue working on it, let me know and I'll reopen the PR. Sorry for not responding for so long!
I would like to take over this PR.