From 642efabfbbba6577a3698a305bac8ce0c693e67f Mon Sep 17 00:00:00 2001 From: boolean_coercion Date: Fri, 12 Feb 2021 11:53:52 +0200 Subject: [PATCH] Fixed typos and updated to matches! where applicable --- clippy_lints/src/from_str_radix_10.rs | 12 ++---------- tests/ui/from_str_radix_10.stderr | 10 +++++----- 2 files changed, 7 insertions(+), 15 deletions(-) diff --git a/clippy_lints/src/from_str_radix_10.rs b/clippy_lints/src/from_str_radix_10.rs index 53cb1e3ecd9..de9add4b6b6 100644 --- a/clippy_lints/src/from_str_radix_10.rs +++ b/clippy_lints/src/from_str_radix_10.rs @@ -46,7 +46,7 @@ impl LateLintPass<'tcx> for FromStrRadix10 { if let TyKind::Path(ty_qpath) = &ty.kind; let ty_res = cx.qpath_res(ty_qpath, ty.hir_id); if let def::Res::PrimTy(prim_ty) = ty_res; - if is_primitive_integer_ty(prim_ty); + if matches!(prim_ty, PrimTy::Int(_) | PrimTy::Uint(_)); // check if the second part of the path indeed calls the associated // function `from_str_radix` @@ -63,7 +63,7 @@ impl LateLintPass<'tcx> for FromStrRadix10 { cx, FROM_STR_RADIX_10, exp.span, - "This call to `from_str_radix` can be shortened to a call to str::parse", + "this call to `from_str_radix` can be replaced with a call to `str::parse`", "try", format!("({}).parse()", orig_string), Applicability::MaybeIncorrect @@ -72,11 +72,3 @@ impl LateLintPass<'tcx> for FromStrRadix10 { } } } - -fn is_primitive_integer_ty(ty: PrimTy) -> bool { - match ty { - PrimTy::Int(_) => true, - PrimTy::Uint(_) => true, - _ => false, - } -} diff --git a/tests/ui/from_str_radix_10.stderr b/tests/ui/from_str_radix_10.stderr index 376d0dd56ea..5557cd3b9ef 100644 --- a/tests/ui/from_str_radix_10.stderr +++ b/tests/ui/from_str_radix_10.stderr @@ -1,4 +1,4 @@ -error: This call to `from_str_radix` can be shortened to a call to str::parse +error: this call to `from_str_radix` can be replaced with a call to `str::parse` --> $DIR/from_str_radix_10.rs:17:5 | LL | u32::from_str_radix("30", 10)?; @@ -6,25 +6,25 @@ LL | u32::from_str_radix("30", 10)?; | = note: `-D clippy::from-str-radix-10` implied by `-D warnings` -error: This call to `from_str_radix` can be shortened to a call to str::parse +error: this call to `from_str_radix` can be replaced with a call to `str::parse` --> $DIR/from_str_radix_10.rs:18:5 | LL | i64::from_str_radix("24", 10)?; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `("24").parse()` -error: This call to `from_str_radix` can be shortened to a call to str::parse +error: this call to `from_str_radix` can be replaced with a call to `str::parse` --> $DIR/from_str_radix_10.rs:19:5 | LL | isize::from_str_radix("100", 10)?; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `("100").parse()` -error: This call to `from_str_radix` can be shortened to a call to str::parse +error: this call to `from_str_radix` can be replaced with a call to `str::parse` --> $DIR/from_str_radix_10.rs:20:5 | LL | u8::from_str_radix("7", 10)?; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `("7").parse()` -error: This call to `from_str_radix` can be shortened to a call to str::parse +error: this call to `from_str_radix` can be replaced with a call to `str::parse` --> $DIR/from_str_radix_10.rs:23:5 | LL | i32::from_str_radix(string, 10)?;