Skip to content

Commit a389c02

Browse files
from_str_radix_10 should be done
1 parent 6472939 commit a389c02

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

clippy_lints/src/from_str_radix_10.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,18 +52,20 @@ impl LateLintPass<'tcx> for FromStrRadix10 {
5252
// function `from_str_radix`
5353
if pathseg.ident.name.as_str() == "from_str_radix";
5454

55-
// check if the second argument resolves to a constant `10`
55+
// check if the second argument is a primitive `10`
5656
if arguments.len() == 2;
57-
if is_constant_10(&arguments[1]);
57+
if let ExprKind::Lit(lit) = &arguments[1].kind;
58+
if let rustc_ast::ast::LitKind::Int(10, _) = lit.node;
5859

5960
then {
61+
let orig_string = crate::utils::snippet(cx, arguments[0].span, "string");
6062
span_lint_and_sugg(
6163
cx,
6264
FROM_STR_RADIX_10,
6365
exp.span,
6466
"This call to `from_str_radix` can be shortened to a call to str::parse",
6567
"try",
66-
format!("TODO"),
68+
format!("({}).parse()", orig_string),
6769
Applicability::MachineApplicable
6870
);
6971
}
@@ -77,9 +79,4 @@ fn is_primitive_integer_ty(ty: PrimTy) -> bool {
7779
PrimTy::Uint(_) => true,
7880
_ => false
7981
}
80-
}
81-
82-
fn is_constant_10<'tcx>(expr: &Expr<'tcx>) -> bool {
83-
// TODO
84-
true
8582
}

0 commit comments

Comments
 (0)