]> git.lizzy.rs Git - rust.git/blobdiff - clippy_lints/src/checked_conversions.rs
modify code
[rust.git] / clippy_lints / src / checked_conversions.rs
index 6a2666bc6c0111026890f8ef361af6cb1fa0682d..31cc3698592b35d26440a901ef34a3cb926bda92 100644 (file)
@@ -2,7 +2,7 @@
 
 use clippy_utils::diagnostics::span_lint_and_sugg;
 use clippy_utils::source::snippet_with_applicability;
-use clippy_utils::{meets_msrv, SpanlessEq};
+use clippy_utils::{meets_msrv, msrvs, SpanlessEq};
 use if_chain::if_chain;
 use rustc_ast::ast::LitKind;
 use rustc_errors::Applicability;
 use rustc_semver::RustcVersion;
 use rustc_session::{declare_tool_lint, impl_lint_pass};
 
-const CHECKED_CONVERSIONS_MSRV: RustcVersion = RustcVersion::new(1, 34, 0);
-
 declare_clippy_lint! {
-    /// **What it does:** Checks for explicit bounds checking when casting.
-    ///
-    /// **Why is this bad?** Reduces the readability of statements & is error prone.
+    /// ### What it does
+    /// Checks for explicit bounds checking when casting.
     ///
-    /// **Known problems:** None.
+    /// ### Why is this bad?
+    /// Reduces the readability of statements & is error prone.
     ///
-    /// **Example:**
+    /// ### Example
     /// ```rust
     /// # let foo: u32 = 5;
     /// # let _ =
@@ -38,6 +36,7 @@
     /// i32::try_from(foo).is_ok()
     /// # ;
     /// ```
+    #[clippy::version = "1.37.0"]
     pub CHECKED_CONVERSIONS,
     pedantic,
     "`try_from` could replace manual bounds checking when casting"
@@ -58,7 +57,7 @@ pub fn new(msrv: Option<RustcVersion>) -> Self {
 
 impl<'tcx> LateLintPass<'tcx> for CheckedConversions {
     fn check_expr(&mut self, cx: &LateContext<'_>, item: &Expr<'_>) {
-        if !meets_msrv(self.msrv.as_ref(), &CHECKED_CONVERSIONS_MSRV) {
+        if !meets_msrv(self.msrv.as_ref(), &msrvs::TRY_FROM) {
             return;
         }
 
@@ -322,8 +321,8 @@ fn get_implementing_type<'a>(path: &QPath<'_>, candidates: &'a [&str], function:
         if let TyKind::Path(QPath::Resolved(None, tp)) = &ty.kind;
         if let [int] = &*tp.segments;
         then {
-            let name = &int.ident.name.as_str();
-            candidates.iter().find(|c| name == *c).copied()
+            let name = int.ident.name.as_str();
+            candidates.iter().find(|c| &name == *c).copied()
         } else {
             None
         }
@@ -336,8 +335,8 @@ fn int_ty_to_sym<'tcx>(path: &QPath<'_>) -> Option<&'tcx str> {
         if let QPath::Resolved(_, path) = *path;
         if let [ty] = &*path.segments;
         then {
-            let name = &ty.ident.name.as_str();
-            INTS.iter().find(|c| name == *c).copied()
+            let name = ty.ident.name.as_str();
+            INTS.iter().find(|c| &name == *c).copied()
         } else {
             None
         }