]> git.lizzy.rs Git - rust.git/blob - src/docs/from_str_radix_10.txt
[Arithmetic] Consider literals
[rust.git] / src / docs / from_str_radix_10.txt
1 ### What it does
2
3 Checks for function invocations of the form `primitive::from_str_radix(s, 10)`
4
5 ### Why is this bad?
6
7 This specific common use case can be rewritten as `s.parse::<primitive>()`
8 (and in most cases, the turbofish can be removed), which reduces code length
9 and complexity.
10
11 ### Known problems
12
13 This lint may suggest using (&<expression>).parse() instead of <expression>.parse() directly
14 in some cases, which is correct but adds unnecessary complexity to the code.
15
16 ### Example
17 ```
18 let input: &str = get_input();
19 let num = u16::from_str_radix(input, 10)?;
20 ```
21 Use instead:
22 ```
23 let input: &str = get_input();
24 let num: u16 = input.parse()?;
25 ```