From 043732797693ea757c8608416fd8591702225106 Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Wed, 4 Jan 2017 14:14:22 -0800 Subject: [PATCH] Rustup to rustc 1.16.0-nightly (468227129 2017-01-03): More u128 fixes --- clippy_lints/src/consts.rs | 2 ++ clippy_lints/src/functions.rs | 4 +-- clippy_lints/src/types.rs | 46 ++++++++++++++++++++--------------- 3 files changed, 30 insertions(+), 22 deletions(-) diff --git a/clippy_lints/src/consts.rs b/clippy_lints/src/consts.rs index 890baa64d..0fbc71da5 100644 --- a/clippy_lints/src/consts.rs +++ b/clippy_lints/src/consts.rs @@ -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))) }, diff --git a/clippy_lints/src/functions.rs b/clippy_lints/src/functions.rs index 784bca403..7f019e574 100644 --- a/clippy_lints/src/functions.rs +++ b/clippy_lints/src/functions.rs @@ -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); } diff --git a/clippy_lints/src/types.rs b/clippy_lints/src/types.rs index 0b8308933..423071c45 100644 --- a/clippy_lints/src/types.rs +++ b/clippy_lints/src/types.rs @@ -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 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 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 { 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 {