Skip to content

Commit 5995e8e

Browse files
committed
misc: extend let-chain
1 parent 32a216e commit 5995e8e

File tree

1 file changed

+21
-28
lines changed

1 file changed

+21
-28
lines changed

clippy_lints/src/manual_rotate.rs

Lines changed: 21 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -80,38 +80,31 @@ impl LateLintPass<'_> for ManualRotate {
8080
&& let BinOpKind::Add | BinOpKind::BitOr = op.node
8181
&& let Some((l_shift_dir, l_amount, l_expr)) = parse_shift(cx, l)
8282
&& let Some((r_shift_dir, r_amount, r_expr)) = parse_shift(cx, r)
83-
{
84-
if l_shift_dir == r_shift_dir {
85-
return;
86-
}
87-
if !clippy_utils::eq_expr_value(cx, l_expr, r_expr) {
88-
return;
89-
}
90-
let Some(bit_width) = (match cx.typeck_results().expr_ty(expr).kind() {
83+
&& l_shift_dir != r_shift_dir
84+
&& clippy_utils::eq_expr_value(cx, l_expr, r_expr)
85+
&& let Some(bit_width) = match cx.typeck_results().expr_ty(expr).kind() {
9186
ty::Int(itype) => itype.bit_width(),
9287
ty::Uint(itype) => itype.bit_width(),
9388
_ => return,
94-
}) else {
95-
return;
96-
};
97-
if l_amount + r_amount == u128::from(bit_width) {
98-
let (shift_function, amount) = if l_amount < r_amount {
99-
(l_shift_dir, l_amount)
100-
} else {
101-
(r_shift_dir, r_amount)
102-
};
103-
let mut applicability = Applicability::MachineApplicable;
104-
let expr_sugg = sugg::Sugg::hir_with_applicability(cx, l_expr, "_", &mut applicability).maybe_paren();
105-
span_lint_and_sugg(
106-
cx,
107-
MANUAL_ROTATE,
108-
expr.span,
109-
"there is no need to manually implement bit rotation",
110-
"this expression can be rewritten as",
111-
format!("{expr_sugg}.{shift_function}({amount})"),
112-
Applicability::MachineApplicable,
113-
);
11489
}
90+
&& l_amount + r_amount == u128::from(bit_width)
91+
{
92+
let (shift_function, amount) = if l_amount < r_amount {
93+
(l_shift_dir, l_amount)
94+
} else {
95+
(r_shift_dir, r_amount)
96+
};
97+
let mut applicability = Applicability::MachineApplicable;
98+
let expr_sugg = sugg::Sugg::hir_with_applicability(cx, l_expr, "_", &mut applicability).maybe_paren();
99+
span_lint_and_sugg(
100+
cx,
101+
MANUAL_ROTATE,
102+
expr.span,
103+
"there is no need to manually implement bit rotation",
104+
"this expression can be rewritten as",
105+
format!("{expr_sugg}.{shift_function}({amount})"),
106+
Applicability::MachineApplicable,
107+
);
115108
}
116109
}
117110
}

0 commit comments

Comments
 (0)