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 _ =
/// i32::try_from(foo).is_ok()
/// # ;
/// ```
+ #[clippy::version = "1.37.0"]
pub CHECKED_CONVERSIONS,
pedantic,
"`try_from` could replace manual bounds checking when casting"
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;
}
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).cloned()
+ let name = int.ident.name.as_str();
+ candidates.iter().find(|c| &name == *c).copied()
} else {
None
}
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).cloned()
+ let name = ty.ident.name.as_str();
+ INTS.iter().find(|c| &name == *c).copied()
} else {
None
}