Skip to content

Commit 4905af3

Browse files
authored
cmov: address truncation lint for Cmov impl for u8 (#1302)
1 parent 6778336 commit 4905af3

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

cmov/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,21 +70,21 @@ pub trait CmovEq {
7070
}
7171
}
7272

73-
// TODO(tarcieri): address truncation lint
74-
#[allow(clippy::cast_possible_truncation)]
7573
impl Cmov for u8 {
7674
#[inline]
7775
fn cmovnz(&mut self, value: &Self, condition: Condition) {
7876
let mut tmp = *self as u16;
7977
tmp.cmovnz(&(*value as u16), condition);
80-
*self = tmp as u8;
78+
debug_assert!(tmp <= u8::MAX as u16);
79+
*self = (tmp & 0xFF) as u8;
8180
}
8281

8382
#[inline]
8483
fn cmovz(&mut self, value: &Self, condition: Condition) {
8584
let mut tmp = *self as u16;
8685
tmp.cmovz(&(*value as u16), condition);
87-
*self = tmp as u8;
86+
debug_assert!(tmp <= u8::MAX as u16);
87+
*self = (tmp & 0xFF) as u8;
8888
}
8989
}
9090

0 commit comments

Comments
 (0)