Skip to content

Commit b80ac2a

Browse files
Added boilerplate
1 parent 605e9ba commit b80ac2a

File tree

4 files changed

+44
-0
lines changed

4 files changed

+44
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2092,6 +2092,7 @@ Released 2018-09-13
20922092
[`forget_ref`]: https://rust-lang.github.io/rust-clippy/master/index.html#forget_ref
20932093
[`from_iter_instead_of_collect`]: https://rust-lang.github.io/rust-clippy/master/index.html#from_iter_instead_of_collect
20942094
[`from_over_into`]: https://rust-lang.github.io/rust-clippy/master/index.html#from_over_into
2095+
[`from_str_radix_10`]: https://rust-lang.github.io/rust-clippy/master/index.html#from_str_radix_10
20952096
[`future_not_send`]: https://rust-lang.github.io/rust-clippy/master/index.html#future_not_send
20962097
[`get_last_with_len`]: https://rust-lang.github.io/rust-clippy/master/index.html#get_last_with_len
20972098
[`get_unwrap`]: https://rust-lang.github.io/rust-clippy/master/index.html#get_unwrap

clippy_lints/src/from_str_radix_10.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
use rustc_lint::{EarlyLintPass, EarlyContext};
2+
use rustc_session::{declare_lint_pass, declare_tool_lint};
3+
use rustc_ast::ast::*;
4+
5+
declare_clippy_lint! {
6+
/// **What it does:**
7+
/// Checks for function invocations of the form `primitive::from_str_radix(s, 10)`
8+
///
9+
/// **Why is this bad?**
10+
/// This specific common use case can be rewritten as `s.parse::<primitive>()`
11+
/// (and in most cases, the turbofish can be removed), which reduces code length
12+
/// and complexity.
13+
///
14+
/// **Known problems:** None.
15+
///
16+
/// **Example:**
17+
///
18+
/// ```rust
19+
/// let input: &str = get_input();
20+
/// let num = u16::from_str_radix(input, 10)?;
21+
/// ```
22+
/// Use instead:
23+
/// ```rust
24+
/// let input: &str = get_input();
25+
/// let num: u16 = input.parse()?;
26+
/// ```
27+
pub FROM_STR_RADIX_10,
28+
style,
29+
"default lint description"
30+
}
31+
32+
declare_lint_pass!(FromStrRadix10 => [FROM_STR_RADIX_10]);
33+
34+
impl EarlyLintPass for FromStrRadix10 {}

clippy_lints/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ mod floating_point_arithmetic;
210210
mod format;
211211
mod formatting;
212212
mod from_over_into;
213+
mod from_str_radix_10;
213214
mod functions;
214215
mod future_not_send;
215216
mod get_last_with_len;
@@ -637,6 +638,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
637638
&formatting::SUSPICIOUS_ELSE_FORMATTING,
638639
&formatting::SUSPICIOUS_UNARY_OP_FORMATTING,
639640
&from_over_into::FROM_OVER_INTO,
641+
&from_str_radix_10::FROM_STR_RADIX_10,
640642
&functions::DOUBLE_MUST_USE,
641643
&functions::MUST_USE_CANDIDATE,
642644
&functions::MUST_USE_UNIT,
@@ -1468,6 +1470,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
14681470
LintId::of(&formatting::SUSPICIOUS_ELSE_FORMATTING),
14691471
LintId::of(&formatting::SUSPICIOUS_UNARY_OP_FORMATTING),
14701472
LintId::of(&from_over_into::FROM_OVER_INTO),
1473+
LintId::of(&from_str_radix_10::FROM_STR_RADIX_10),
14711474
LintId::of(&functions::DOUBLE_MUST_USE),
14721475
LintId::of(&functions::MUST_USE_UNIT),
14731476
LintId::of(&functions::NOT_UNSAFE_PTR_ARG_DEREF),
@@ -1724,6 +1727,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
17241727
LintId::of(&formatting::SUSPICIOUS_ELSE_FORMATTING),
17251728
LintId::of(&formatting::SUSPICIOUS_UNARY_OP_FORMATTING),
17261729
LintId::of(&from_over_into::FROM_OVER_INTO),
1730+
LintId::of(&from_str_radix_10::FROM_STR_RADIX_10),
17271731
LintId::of(&functions::DOUBLE_MUST_USE),
17281732
LintId::of(&functions::MUST_USE_UNIT),
17291733
LintId::of(&functions::RESULT_UNIT_ERR),

tests/ui/from_str_radix_10.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#![warn(clippy::from_str_radix_10)]
2+
3+
fn main() {
4+
// test code goes here
5+
}

0 commit comments

Comments
 (0)