mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-24 05:33:27 +00:00
Rustup to rustc 1.16.0-nightly (468227129 2017-01-03): More u128 fixes
This commit is contained in:
parent
e02fac4896
commit
0437327976
3 changed files with 30 additions and 22 deletions
|
@ -185,6 +185,7 @@ pub fn lit_to_constant(lit: &LitKind) -> Constant {
|
|||
LitKind::Int(value, LitIntType::Unsigned(UintTy::U16)) => Constant::Int(ConstInt::U16(value as u16)),
|
||||
LitKind::Int(value, LitIntType::Unsigned(UintTy::U32)) => Constant::Int(ConstInt::U32(value as u32)),
|
||||
LitKind::Int(value, LitIntType::Unsigned(UintTy::U64)) => Constant::Int(ConstInt::U64(value as u64)),
|
||||
LitKind::Int(value, LitIntType::Unsigned(UintTy::U128)) => Constant::Int(ConstInt::U128(value as u128)),
|
||||
LitKind::Int(value, LitIntType::Unsigned(UintTy::Us)) => {
|
||||
Constant::Int(ConstInt::Usize(ConstUsize::Us32(value as u32)))
|
||||
},
|
||||
|
@ -192,6 +193,7 @@ pub fn lit_to_constant(lit: &LitKind) -> Constant {
|
|||
LitKind::Int(value, LitIntType::Signed(IntTy::I16)) => Constant::Int(ConstInt::I16(value as i16)),
|
||||
LitKind::Int(value, LitIntType::Signed(IntTy::I32)) => Constant::Int(ConstInt::I32(value as i32)),
|
||||
LitKind::Int(value, LitIntType::Signed(IntTy::I64)) => Constant::Int(ConstInt::I64(value as i64)),
|
||||
LitKind::Int(value, LitIntType::Signed(IntTy::I128)) => Constant::Int(ConstInt::I128(value as i128)),
|
||||
LitKind::Int(value, LitIntType::Signed(IntTy::Is)) => {
|
||||
Constant::Int(ConstInt::Isize(ConstIsize::Is32(value as i32)))
|
||||
},
|
||||
|
|
|
@ -106,13 +106,13 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Functions {
|
|||
}
|
||||
|
||||
fn check_trait_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx hir::TraitItem) {
|
||||
if let hir::TraitItemKind::Method(ref sig, eid) = item.node {
|
||||
if let hir::TraitItemKind::Method(ref sig, ref eid) = item.node {
|
||||
// don't lint extern functions decls, it's not their fault
|
||||
if sig.abi == Abi::Rust {
|
||||
self.check_arg_number(cx, &sig.decl, item.span);
|
||||
}
|
||||
|
||||
if let hir::TraitMethod::Provided(eid) = eid {
|
||||
if let hir::TraitMethod::Provided(eid) = *eid {
|
||||
let body = cx.tcx.map.body(eid);
|
||||
self.check_raw_ptr(cx, sig.unsafety, &sig.decl, &body, item.id);
|
||||
}
|
||||
|
|
|
@ -326,7 +326,7 @@ declare_lint! {
|
|||
/// **Example:**
|
||||
/// ```rust
|
||||
/// let y: i8 = -1;
|
||||
/// y as u64 // will return 18446744073709551615
|
||||
/// y as u128 // will return 18446744073709551615
|
||||
/// ```
|
||||
declare_lint! {
|
||||
pub CAST_SIGN_LOSS,
|
||||
|
@ -889,12 +889,14 @@ fn detect_extreme_expr<'a>(cx: &LateContext, expr: &'a Expr) -> Option<ExtremeEx
|
|||
(&ty::TyInt(IntTy::I16), Integral(I16(::std::i16::MIN))) |
|
||||
(&ty::TyInt(IntTy::I32), Integral(I32(::std::i32::MIN))) |
|
||||
(&ty::TyInt(IntTy::I64), Integral(I64(::std::i64::MIN))) |
|
||||
(&ty::TyInt(IntTy::I128), Integral(I128(::std::i128::MIN))) |
|
||||
(&ty::TyUint(UintTy::Us), Integral(Usize(Us32(::std::u32::MIN)))) |
|
||||
(&ty::TyUint(UintTy::Us), Integral(Usize(Us64(::std::u64::MIN)))) |
|
||||
(&ty::TyUint(UintTy::U8), Integral(U8(::std::u8::MIN))) |
|
||||
(&ty::TyUint(UintTy::U16), Integral(U16(::std::u16::MIN))) |
|
||||
(&ty::TyUint(UintTy::U32), Integral(U32(::std::u32::MIN))) |
|
||||
(&ty::TyUint(UintTy::U64), Integral(U64(::std::u64::MIN))) => Minimum,
|
||||
(&ty::TyUint(UintTy::U64), Integral(U64(::std::u64::MIN))) |
|
||||
(&ty::TyUint(UintTy::U128), Integral(U128(::std::u128::MIN))) => Minimum,
|
||||
|
||||
(&ty::TyBool, Bool(true)) |
|
||||
(&ty::TyInt(IntTy::Is), Integral(Isize(Is32(::std::i32::MAX)))) |
|
||||
|
@ -903,12 +905,14 @@ fn detect_extreme_expr<'a>(cx: &LateContext, expr: &'a Expr) -> Option<ExtremeEx
|
|||
(&ty::TyInt(IntTy::I16), Integral(I16(::std::i16::MAX))) |
|
||||
(&ty::TyInt(IntTy::I32), Integral(I32(::std::i32::MAX))) |
|
||||
(&ty::TyInt(IntTy::I64), Integral(I64(::std::i64::MAX))) |
|
||||
(&ty::TyInt(IntTy::I128), Integral(I128(::std::i128::MAX))) |
|
||||
(&ty::TyUint(UintTy::Us), Integral(Usize(Us32(::std::u32::MAX)))) |
|
||||
(&ty::TyUint(UintTy::Us), Integral(Usize(Us64(::std::u64::MAX)))) |
|
||||
(&ty::TyUint(UintTy::U8), Integral(U8(::std::u8::MAX))) |
|
||||
(&ty::TyUint(UintTy::U16), Integral(U16(::std::u16::MAX))) |
|
||||
(&ty::TyUint(UintTy::U32), Integral(U32(::std::u32::MAX))) |
|
||||
(&ty::TyUint(UintTy::U64), Integral(U64(::std::u64::MAX))) => Maximum,
|
||||
(&ty::TyUint(UintTy::U64), Integral(U64(::std::u64::MAX))) |
|
||||
(&ty::TyUint(UintTy::U128), Integral(U128(::std::u128::MAX))) => Maximum,
|
||||
|
||||
_ => return None,
|
||||
};
|
||||
|
@ -985,19 +989,19 @@ impl LintPass for InvalidUpcastComparisons {
|
|||
|
||||
#[derive(Copy, Clone, Debug, Eq)]
|
||||
enum FullInt {
|
||||
S(i64),
|
||||
U(u64),
|
||||
S(i128),
|
||||
U(u128),
|
||||
}
|
||||
|
||||
impl FullInt {
|
||||
#[allow(cast_sign_loss)]
|
||||
fn cmp_s_u(s: i64, u: u64) -> Ordering {
|
||||
fn cmp_s_u(s: i128, u: u128) -> Ordering {
|
||||
if s < 0 {
|
||||
Ordering::Less
|
||||
} else if u > (i64::max_value() as u64) {
|
||||
} else if u > (i128::max_value() as u128) {
|
||||
Ordering::Greater
|
||||
} else {
|
||||
(s as u64).cmp(&u)
|
||||
(s as u128).cmp(&u)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1034,20 +1038,22 @@ fn numeric_cast_precast_bounds<'a>(cx: &LateContext, expr: &'a Expr) -> Option<(
|
|||
match cx.tcx.tables().expr_ty(cast_exp).sty {
|
||||
TyInt(int_ty) => {
|
||||
Some(match int_ty {
|
||||
IntTy::I8 => (FullInt::S(i8::min_value() as i64), FullInt::S(i8::max_value() as i64)),
|
||||
IntTy::I16 => (FullInt::S(i16::min_value() as i64), FullInt::S(i16::max_value() as i64)),
|
||||
IntTy::I32 => (FullInt::S(i32::min_value() as i64), FullInt::S(i32::max_value() as i64)),
|
||||
IntTy::I64 => (FullInt::S(i64::min_value() as i64), FullInt::S(i64::max_value() as i64)),
|
||||
IntTy::Is => (FullInt::S(isize::min_value() as i64), FullInt::S(isize::max_value() as i64)),
|
||||
IntTy::I8 => (FullInt::S(i8::min_value() as i128), FullInt::S(i8::max_value() as i128)),
|
||||
IntTy::I16 => (FullInt::S(i16::min_value() as i128), FullInt::S(i16::max_value() as i128)),
|
||||
IntTy::I32 => (FullInt::S(i32::min_value() as i128), FullInt::S(i32::max_value() as i128)),
|
||||
IntTy::I64 => (FullInt::S(i64::min_value() as i128), FullInt::S(i64::max_value() as i128)),
|
||||
IntTy::I128 => (FullInt::S(i128::min_value() as i128), FullInt::S(i128::max_value() as i128)),
|
||||
IntTy::Is => (FullInt::S(isize::min_value() as i128), FullInt::S(isize::max_value() as i128)),
|
||||
})
|
||||
},
|
||||
TyUint(uint_ty) => {
|
||||
Some(match uint_ty {
|
||||
UintTy::U8 => (FullInt::U(u8::min_value() as u64), FullInt::U(u8::max_value() as u64)),
|
||||
UintTy::U16 => (FullInt::U(u16::min_value() as u64), FullInt::U(u16::max_value() as u64)),
|
||||
UintTy::U32 => (FullInt::U(u32::min_value() as u64), FullInt::U(u32::max_value() as u64)),
|
||||
UintTy::U64 => (FullInt::U(u64::min_value() as u64), FullInt::U(u64::max_value() as u64)),
|
||||
UintTy::Us => (FullInt::U(usize::min_value() as u64), FullInt::U(usize::max_value() as u64)),
|
||||
UintTy::U8 => (FullInt::U(u8::min_value() as u128), FullInt::U(u8::max_value() as u128)),
|
||||
UintTy::U16 => (FullInt::U(u16::min_value() as u128), FullInt::U(u16::max_value() as u128)),
|
||||
UintTy::U32 => (FullInt::U(u32::min_value() as u128), FullInt::U(u32::max_value() as u128)),
|
||||
UintTy::U64 => (FullInt::U(u64::min_value() as u128), FullInt::U(u64::max_value() as u128)),
|
||||
UintTy::U128 => (FullInt::U(u128::min_value() as u128), FullInt::U(u128::max_value() as u128)),
|
||||
UintTy::Us => (FullInt::U(usize::min_value() as u128), FullInt::U(usize::max_value() as u128)),
|
||||
})
|
||||
},
|
||||
_ => None,
|
||||
|
@ -1067,8 +1073,8 @@ fn node_as_const_fullint(cx: &LateContext, expr: &Expr) -> Option<FullInt> {
|
|||
Ok(val) => {
|
||||
if let Integral(const_int) = val {
|
||||
Some(match const_int.erase_type() {
|
||||
ConstInt::InferSigned(x) => FullInt::S(x as i64),
|
||||
ConstInt::Infer(x) => FullInt::U(x as u64),
|
||||
ConstInt::InferSigned(x) => FullInt::S(x as i128),
|
||||
ConstInt::Infer(x) => FullInt::U(x as u128),
|
||||
_ => unreachable!(),
|
||||
})
|
||||
} else {
|
||||
|
|
Loading…
Reference in a new issue