Skip to content

Commit 6e0c7d6

Browse files
authored
Fix bad_bit_mask ICE for overloaded bit ops (#16937)
Closes #16935 changelog: [`bad_bit_mask`] fix ICE for overloaded bit ops
2 parents da29c3e + 5c971e0 commit 6e0c7d6

2 files changed

Lines changed: 24 additions & 1 deletion

File tree

clippy_lints/src/operators/bit_mask.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ fn check_compare<'a>(cx: &LateContext<'a>, bit_op: &Expr<'a>, cmp_op: BinOpKind,
4343
}
4444
if let Some(mask) = fetch_int_literal(cx, right).or_else(|| fetch_int_literal(cx, left)) {
4545
let ty = cx.typeck_results().expr_ty(bit_op);
46-
if !ty.is_ptr_sized_integral()
46+
if ty.is_primitive()
47+
&& !ty.is_ptr_sized_integral()
4748
&& let bits = ty.primitive_size(cx.tcx)
4849
{
4950
// Strip high bits that don't fit into the result type as they won't be used in the comparison

tests/ui/bit_masks.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,3 +99,25 @@ mod issue16781 {
9999
x & 0x70 == 0x11 << 4
100100
}
101101
}
102+
103+
mod issue16935 {
104+
struct Wrapper(usize);
105+
106+
impl std::ops::BitAnd<usize> for Wrapper {
107+
type Output = Self;
108+
109+
fn bitand(self, rhs: usize) -> Self::Output {
110+
Self(self.0 & rhs)
111+
}
112+
}
113+
114+
impl PartialEq<usize> for Wrapper {
115+
fn eq(&self, other: &usize) -> bool {
116+
self.0.eq(other)
117+
}
118+
}
119+
120+
fn check(value: Wrapper) -> bool {
121+
value & 0x1 != 0
122+
}
123+
}

0 commit comments

Comments
 (0)