diff --git a/clippy_lints/src/consts.rs b/clippy_lints/src/consts.rs index b84430e68..5d509ef76 100644 --- a/clippy_lints/src/consts.rs +++ b/clippy_lints/src/consts.rs @@ -230,6 +230,7 @@ impl<'c, 'cc> ConstEvalLateContext<'c, 'cc> { } } + #[allow(clippy::cast_possible_wrap)] fn constant_not(&self, o: &Constant, ty: ty::Ty<'_>) -> Option { use self::Constant::*; match *o { @@ -343,10 +344,10 @@ impl<'c, 'cc> ConstEvalLateContext<'c, 'cc> { 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 8fba45de8..313175aee 100644 --- a/clippy_lints/src/enum_clike.rs +++ b/clippy_lints/src/enum_clike.rs @@ -53,7 +53,7 @@ impl LintPass for UnportableVariant { } 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 7282e5064..2a9b1cb0a 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);