From 0a43dcfd042dbc7a8bd30a17a5bcf53c80c497f9 Mon Sep 17 00:00:00 2001 From: pJunger Date: Sun, 12 May 2019 21:53:28 +0200 Subject: [PATCH] Fixed more lint findings. --- clippy_lints/src/checked_conversions.rs | 6 ++---- clippy_lints/src/enum_clike.rs | 3 ++- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/clippy_lints/src/checked_conversions.rs b/clippy_lints/src/checked_conversions.rs index 0269a1959b7..48d941f9f8b 100644 --- a/clippy_lints/src/checked_conversions.rs +++ b/clippy_lints/src/checked_conversions.rs @@ -123,9 +123,7 @@ impl<'a> Conversion<'a> { /// Checks if the to-type is the same (if there is a type constraint) fn has_compatible_to_type(&self, other: &Self) -> bool { - transpose(self.to_type.as_ref(), other.to_type.as_ref()) - .map(|(l, r)| l == r) - .unwrap_or(true) + transpose(self.to_type.as_ref(), other.to_type.as_ref()).map_or(true, |(l, r)| l == r) } /// Try to construct a new conversion if the conversion type is valid @@ -149,7 +147,7 @@ impl<'a> Conversion<'a> { impl ConversionType { /// Creates a conversion type if the type is allowed & conversion is valid - fn try_new(from: &str, to: &str) -> Option { + fn try_new(from: &str, to: &str) -> Option { if UNSIGNED_TYPES.contains(&from) { Some(ConversionType::FromUnsigned) } else if SIGNED_TYPES.contains(&from) { diff --git a/clippy_lints/src/enum_clike.rs b/clippy_lints/src/enum_clike.rs index 90cb78ae036..f289c278a8c 100644 --- a/clippy_lints/src/enum_clike.rs +++ b/clippy_lints/src/enum_clike.rs @@ -10,6 +10,7 @@ use rustc::ty; use rustc::ty::subst::InternalSubsts; use rustc::ty::util::IntTypeExt; use rustc::{declare_lint_pass, declare_tool_lint}; +use std::convert::TryFrom; use syntax::ast::{IntTy, UintTy}; declare_clippy_lint! { @@ -65,7 +66,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnportableVariant { match ty.sty { ty::Int(IntTy::Isize) => { let val = ((val as i128) << 64) >> 64; - if val <= i128::from(i32::max_value()) && val >= i128::from(i32::min_value()) { + if i32::try_from(val).is_ok() { continue; } },