2
0
Fork 0
mirror of https://github.com/rust-lang/rust-clippy synced 2024-12-25 04:23:22 +00:00
rust-clippy/tests/ui/from_str_radix_10.fixed

62 lines
2.1 KiB
Rust
Raw Normal View History

2023-07-27 11:40:22 +00:00
#![warn(clippy::from_str_radix_10)]
mod some_mod {
// fake function that shouldn't trigger the lint
pub fn from_str_radix(_: &str, _: u32) -> Result<(), std::num::ParseIntError> {
unimplemented!()
}
}
// fake function that shouldn't trigger the lint
fn from_str_radix(_: &str, _: u32) -> Result<(), std::num::ParseIntError> {
unimplemented!()
}
// to test parenthesis addition
struct Test;
impl std::ops::Add<Test> for Test {
type Output = &'static str;
fn add(self, _: Self) -> Self::Output {
"304"
}
}
fn main() -> Result<(), Box<dyn std::error::Error>> {
// all of these should trigger the lint
"30".parse::<u32>()?;
//~^ ERROR: this call to `from_str_radix` can be replaced with a call to `str::parse`
//~| NOTE: `-D clippy::from-str-radix-10` implied by `-D warnings`
2023-07-27 11:40:22 +00:00
"24".parse::<i64>()?;
//~^ ERROR: this call to `from_str_radix` can be replaced with a call to `str::parse`
2023-07-27 11:40:22 +00:00
"100".parse::<isize>()?;
//~^ ERROR: this call to `from_str_radix` can be replaced with a call to `str::parse`
2023-07-27 11:40:22 +00:00
"7".parse::<u8>()?;
//~^ ERROR: this call to `from_str_radix` can be replaced with a call to `str::parse`
2023-07-27 11:40:22 +00:00
("10".to_owned() + "5").parse::<u16>()?;
//~^ ERROR: this call to `from_str_radix` can be replaced with a call to `str::parse`
2023-07-27 11:40:22 +00:00
(Test + Test).parse::<i128>()?;
//~^ ERROR: this call to `from_str_radix` can be replaced with a call to `str::parse`
2023-07-27 11:40:22 +00:00
let string = "300";
string.parse::<i32>()?;
//~^ ERROR: this call to `from_str_radix` can be replaced with a call to `str::parse`
2023-07-27 11:40:22 +00:00
let stringier = "400".to_string();
stringier.parse::<i32>()?;
//~^ ERROR: this call to `from_str_radix` can be replaced with a call to `str::parse`
2023-07-27 11:40:22 +00:00
// none of these should trigger the lint
u16::from_str_radix("20", 3)?;
i32::from_str_radix("45", 12)?;
usize::from_str_radix("10", 16)?;
i128::from_str_radix("10", 13)?;
some_mod::from_str_radix("50", 10)?;
some_mod::from_str_radix("50", 6)?;
from_str_radix("50", 10)?;
from_str_radix("50", 6)?;
Ok(())
}