#![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 for Test { type Output = &'static str; fn add(self, _: Self) -> Self::Output { "304" } } fn main() -> Result<(), Box> { // all of these should trigger the lint "30".parse::()?; //~^ from_str_radix_10 "24".parse::()?; //~^ from_str_radix_10 "100".parse::()?; //~^ from_str_radix_10 "7".parse::()?; //~^ from_str_radix_10 ("10".to_owned() + "5").parse::()?; //~^ from_str_radix_10 (Test + Test).parse::()?; //~^ from_str_radix_10 let string = "300"; string.parse::()?; //~^ from_str_radix_10 let stringier = "400".to_string(); stringier.parse::()?; //~^ from_str_radix_10 // 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(()) } // https://github.com/rust-lang/rust-clippy/issues/12731 fn issue_12731() { const A: Result = u32::from_str_radix("123", 10); const B: () = { let _ = u32::from_str_radix("123", 10); }; const fn foo() { let _ = u32::from_str_radix("123", 10); } } fn fix_str_ref_check() { #![allow(clippy::needless_borrow)] let s = "1"; let _ = s.parse::().unwrap(); //~^ from_str_radix_10 let s_ref = &s; let _ = s_ref.parse::().unwrap(); //~^ from_str_radix_10 }