diff --git a/clippy_lints/src/consts.rs b/clippy_lints/src/consts.rs index b84430e6819..5d509ef76f3 100644 --- a/clippy_lints/src/consts.rs +++ b/clippy_lints/src/consts.rs @@ -230,6 +230,7 @@ pub fn expr(&mut self, e: &Expr) -> Option { } } + #[allow(clippy::cast_possible_wrap)] fn constant_not(&self, o: &Constant, ty: ty::Ty<'_>) -> Option { use self::Constant::*; match *o { @@ -343,10 +344,10 @@ fn binop(&mut self, op: BinOp, left: &Expr, right: &Expr) -> Option { BinOpKind::Div if r != 0 => l.checked_div(r).map(zext), BinOpKind::Rem if r != 0 => l.checked_rem(r).map(zext), BinOpKind::Shr => l.checked_shr( - (r as u128).try_into().expect("shift too large") + r.try_into().expect("invalid shift") ).map(zext), BinOpKind::Shl => l.checked_shl( - (r as u128).try_into().expect("shift too large") + r.try_into().expect("invalid shift") ).map(zext), BinOpKind::BitXor => Some(zext(l ^ r)), BinOpKind::BitOr => Some(zext(l | r)), diff --git a/clippy_lints/src/enum_clike.rs b/clippy_lints/src/enum_clike.rs index 8fba45de8ce..313175aee84 100644 --- a/clippy_lints/src/enum_clike.rs +++ b/clippy_lints/src/enum_clike.rs @@ -53,7 +53,7 @@ fn get_lints(&self) -> LintArray { } impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnportableVariant { - #[allow(clippy::cast_possible_truncation, clippy::cast_sign_loss)] + #[allow(clippy::cast_possible_truncation, clippy::cast_possible_wrap, clippy::cast_sign_loss)] fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item) { if cx.tcx.data_layout.pointer_size.bits() != 64 { return; diff --git a/clippy_lints/src/utils/mod.rs b/clippy_lints/src/utils/mod.rs index 7282e5064c3..2a9b1cb0a10 100644 --- a/clippy_lints/src/utils/mod.rs +++ b/clippy_lints/src/utils/mod.rs @@ -971,12 +971,14 @@ pub fn int_bits(tcx: TyCtxt<'_, '_, '_>, ity: ast::IntTy) -> u64 { layout::Integer::from_attr(tcx, attr::IntType::SignedInt(ity)).size().bits() } +#[allow(clippy::cast_possible_wrap)] /// Turn a constant int byte representation into an i128 pub fn sext(tcx: TyCtxt<'_, '_, '_>, u: u128, ity: ast::IntTy) -> i128 { let amt = 128 - int_bits(tcx, ity); ((u as i128) << amt) >> amt } +#[allow(clippy::cast_sign_loss)] /// clip unused bytes pub fn unsext(tcx: TyCtxt<'_, '_, '_>, u: i128, ity: ast::IntTy) -> u128 { let amt = 128 - int_bits(tcx, ity);