rust-clippy/clippy_lints/src/from_str_radix_10.rs

35 lines
993 B
Rust
Raw Normal View History

2021-02-10 19:47:04 +00:00
use rustc_lint::{EarlyLintPass, EarlyContext};
use rustc_session::{declare_lint_pass, declare_tool_lint};
use rustc_ast::ast::*;
declare_clippy_lint! {
/// **What it does:**
/// Checks for function invocations of the form `primitive::from_str_radix(s, 10)`
///
/// **Why is this bad?**
/// This specific common use case can be rewritten as `s.parse::<primitive>()`
/// (and in most cases, the turbofish can be removed), which reduces code length
/// and complexity.
///
/// **Known problems:** None.
///
/// **Example:**
///
/// ```rust
/// let input: &str = get_input();
/// let num = u16::from_str_radix(input, 10)?;
/// ```
/// Use instead:
/// ```rust
/// let input: &str = get_input();
/// let num: u16 = input.parse()?;
/// ```
pub FROM_STR_RADIX_10,
style,
"default lint description"
}
declare_lint_pass!(FromStrRadix10 => [FROM_STR_RADIX_10]);
impl EarlyLintPass for FromStrRadix10 {}