diff options
| author | Devon Hollowood <devonhollowood@gmail.com> | 2018-10-08 22:34:10 -0700 |
|---|---|---|
| committer | Devon Hollowood <devonhollowood@gmail.com> | 2018-10-08 22:34:10 -0700 |
| commit | 2b9abc5daa67120e9b8b711885b71a4c63399921 (patch) | |
| tree | 2112141c6280bdc41da05b2eab67416431a863de | |
| parent | eef2e8948b4f0de21669231933739ef0d0f0017a (diff) | |
| download | rust-2b9abc5daa67120e9b8b711885b71a4c63399921.tar.gz rust-2b9abc5daa67120e9b8b711885b71a4c63399921.zip | |
Fix cast_possible_wrap and cast_sign_loss warnings
| -rw-r--r-- | clippy_lints/src/consts.rs | 5 | ||||
| -rw-r--r-- | clippy_lints/src/enum_clike.rs | 2 | ||||
| -rw-r--r-- | clippy_lints/src/utils/mod.rs | 2 |
3 files changed, 6 insertions, 3 deletions
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 @@ impl<'c, 'cc> ConstEvalLateContext<'c, 'cc> { } } + #[allow(clippy::cast_possible_wrap)] fn constant_not(&self, o: &Constant, ty: ty::Ty<'_>) -> Option<Constant> { 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 8fba45de8ce..313175aee84 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 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); |
