diff options
| author | boolean_coercion <booleancoercion@gmail.com> | 2021-02-11 12:30:23 +0200 |
|---|---|---|
| committer | boolean_coercion <booleancoercion@gmail.com> | 2021-02-12 11:54:22 +0200 |
| commit | a389c02461107a71da042c1a9dbf4c0e597df3b4 (patch) | |
| tree | 9121a5e576f8e1db04005668df1ab033281c3adc | |
| parent | 64729390a1b2b6b05f8a4407658163ddff4d017e (diff) | |
| download | rust-a389c02461107a71da042c1a9dbf4c0e597df3b4.tar.gz rust-a389c02461107a71da042c1a9dbf4c0e597df3b4.zip | |
from_str_radix_10 should be done
| -rw-r--r-- | clippy_lints/src/from_str_radix_10.rs | 13 |
1 files changed, 5 insertions, 8 deletions
diff --git a/clippy_lints/src/from_str_radix_10.rs b/clippy_lints/src/from_str_radix_10.rs index 612ea9ae62c..57661e0f9bc 100644 --- a/clippy_lints/src/from_str_radix_10.rs +++ b/clippy_lints/src/from_str_radix_10.rs @@ -52,18 +52,20 @@ impl LateLintPass<'tcx> for FromStrRadix10 { // function `from_str_radix` if pathseg.ident.name.as_str() == "from_str_radix"; - // check if the second argument resolves to a constant `10` + // check if the second argument is a primitive `10` if arguments.len() == 2; - if is_constant_10(&arguments[1]); + if let ExprKind::Lit(lit) = &arguments[1].kind; + if let rustc_ast::ast::LitKind::Int(10, _) = lit.node; then { + let orig_string = crate::utils::snippet(cx, arguments[0].span, "string"); span_lint_and_sugg( cx, FROM_STR_RADIX_10, exp.span, "This call to `from_str_radix` can be shortened to a call to str::parse", "try", - format!("TODO"), + format!("({}).parse()", orig_string), Applicability::MachineApplicable ); } @@ -77,9 +79,4 @@ fn is_primitive_integer_ty(ty: PrimTy) -> bool { PrimTy::Uint(_) => true, _ => false } -} - -fn is_constant_10<'tcx>(expr: &Expr<'tcx>) -> bool { - // TODO - true } \ No newline at end of file |
