mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-10 23:24:24 +00:00
Limit the identity_op lint to integral operands.
If operands are being applied to non-integers, then the lint is likely wrong.
This commit is contained in:
parent
adba132411
commit
ba70842c62
1 changed files with 7 additions and 4 deletions
|
@ -61,10 +61,13 @@ impl<'tcx> LateLintPass<'tcx> for IdentityOp {
|
|||
}
|
||||
|
||||
fn is_allowed(cx: &LateContext<'_>, cmp: BinOp, left: &Expr<'_>, right: &Expr<'_>) -> bool {
|
||||
// `1 << 0` is a common pattern in bit manipulation code
|
||||
cmp.node == BinOpKind::Shl
|
||||
&& constant_simple(cx, cx.typeck_results(), right) == Some(Constant::Int(0))
|
||||
&& constant_simple(cx, cx.typeck_results(), left) == Some(Constant::Int(1))
|
||||
// This lint applies to integers
|
||||
!cx.typeck_results().expr_ty(left).is_integral()
|
||||
|| !cx.typeck_results().expr_ty(right).is_integral()
|
||||
// `1 << 0` is a common pattern in bit manipulation code
|
||||
|| (cmp.node == BinOpKind::Shl
|
||||
&& constant_simple(cx, cx.typeck_results(), right) == Some(Constant::Int(0))
|
||||
&& constant_simple(cx, cx.typeck_results(), left) == Some(Constant::Int(1)))
|
||||
}
|
||||
|
||||
fn check(cx: &LateContext<'_>, e: &Expr<'_>, m: i8, span: Span, arg: Span) {
|
||||
|
|
Loading…
Reference in a new issue