Skip to content

Commit 2b9abc5

Browse files
Fix cast_possible_wrap and cast_sign_loss warnings
1 parent eef2e89 commit 2b9abc5

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

clippy_lints/src/consts.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ impl<'c, 'cc> ConstEvalLateContext<'c, 'cc> {
230230
}
231231
}
232232

233+
#[allow(clippy::cast_possible_wrap)]
233234
fn constant_not(&self, o: &Constant, ty: ty::Ty<'_>) -> Option<Constant> {
234235
use self::Constant::*;
235236
match *o {
@@ -343,10 +344,10 @@ impl<'c, 'cc> ConstEvalLateContext<'c, 'cc> {
343344
BinOpKind::Div if r != 0 => l.checked_div(r).map(zext),
344345
BinOpKind::Rem if r != 0 => l.checked_rem(r).map(zext),
345346
BinOpKind::Shr => l.checked_shr(
346-
(r as u128).try_into().expect("shift too large")
347+
r.try_into().expect("invalid shift")
347348
).map(zext),
348349
BinOpKind::Shl => l.checked_shl(
349-
(r as u128).try_into().expect("shift too large")
350+
r.try_into().expect("invalid shift")
350351
).map(zext),
351352
BinOpKind::BitXor => Some(zext(l ^ r)),
352353
BinOpKind::BitOr => Some(zext(l | r)),

clippy_lints/src/enum_clike.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ impl LintPass for UnportableVariant {
5353
}
5454

5555
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnportableVariant {
56-
#[allow(clippy::cast_possible_truncation, clippy::cast_sign_loss)]
56+
#[allow(clippy::cast_possible_truncation, clippy::cast_possible_wrap, clippy::cast_sign_loss)]
5757
fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item) {
5858
if cx.tcx.data_layout.pointer_size.bits() != 64 {
5959
return;

clippy_lints/src/utils/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -971,12 +971,14 @@ pub fn int_bits(tcx: TyCtxt<'_, '_, '_>, ity: ast::IntTy) -> u64 {
971971
layout::Integer::from_attr(tcx, attr::IntType::SignedInt(ity)).size().bits()
972972
}
973973

974+
#[allow(clippy::cast_possible_wrap)]
974975
/// Turn a constant int byte representation into an i128
975976
pub fn sext(tcx: TyCtxt<'_, '_, '_>, u: u128, ity: ast::IntTy) -> i128 {
976977
let amt = 128 - int_bits(tcx, ity);
977978
((u as i128) << amt) >> amt
978979
}
979980

981+
#[allow(clippy::cast_sign_loss)]
980982
/// clip unused bytes
981983
pub fn unsext(tcx: TyCtxt<'_, '_, '_>, u: i128, ity: ast::IntTy) -> u128 {
982984
let amt = 128 - int_bits(tcx, ity);

0 commit comments

Comments
 (0)