Fix cast_possible_wrap and cast_sign_loss warnings
This commit is contained in:
parent
eef2e8948b
commit
2b9abc5daa
@ -230,6 +230,7 @@ pub fn expr(&mut self, e: &Expr) -> Option<Constant> {
|
||||
}
|
||||
}
|
||||
|
||||
#[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 @@ fn binop(&mut self, op: BinOp, left: &Expr, right: &Expr) -> Option<Constant> {
|
||||
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)),
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user