]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/tests/ui/from_str_radix_10.rs
Auto merge of #102717 - beetrees:repr128-c-style-debuginfo, r=nagisa
[rust.git] / src / tools / clippy / tests / ui / from_str_radix_10.rs
1 #![warn(clippy::from_str_radix_10)]
2
3 mod some_mod {
4     // fake function that shouldn't trigger the lint
5     pub fn from_str_radix(_: &str, _: u32) -> Result<(), std::num::ParseIntError> {
6         unimplemented!()
7     }
8 }
9
10 // fake function that shouldn't trigger the lint
11 fn from_str_radix(_: &str, _: u32) -> Result<(), std::num::ParseIntError> {
12     unimplemented!()
13 }
14
15 // to test parenthesis addition
16 struct Test;
17
18 impl std::ops::Add<Test> for Test {
19     type Output = &'static str;
20
21     fn add(self, _: Self) -> Self::Output {
22         "304"
23     }
24 }
25
26 fn main() -> Result<(), Box<dyn std::error::Error>> {
27     // all of these should trigger the lint
28     u32::from_str_radix("30", 10)?;
29     i64::from_str_radix("24", 10)?;
30     isize::from_str_radix("100", 10)?;
31     u8::from_str_radix("7", 10)?;
32     u16::from_str_radix(&("10".to_owned() + "5"), 10)?;
33     i128::from_str_radix(Test + Test, 10)?;
34
35     let string = "300";
36     i32::from_str_radix(string, 10)?;
37
38     let stringier = "400".to_string();
39     i32::from_str_radix(&stringier, 10)?;
40
41     // none of these should trigger the lint
42     u16::from_str_radix("20", 3)?;
43     i32::from_str_radix("45", 12)?;
44     usize::from_str_radix("10", 16)?;
45     i128::from_str_radix("10", 13)?;
46     some_mod::from_str_radix("50", 10)?;
47     some_mod::from_str_radix("50", 6)?;
48     from_str_radix("50", 10)?;
49     from_str_radix("50", 6)?;
50
51     Ok(())
52 }