]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/tests/ui/identity_conversion.rs
Add 'src/tools/clippy/' from commit 'd2708873ef711ec8ab45df1e984ecf24a96cd369'
[rust.git] / src / tools / clippy / tests / ui / identity_conversion.rs
1 // run-rustfix
2
3 #![deny(clippy::identity_conversion)]
4
5 fn test_generic<T: Copy>(val: T) -> T {
6     let _ = T::from(val);
7     val.into()
8 }
9
10 fn test_generic2<T: Copy + Into<i32> + Into<U>, U: From<T>>(val: T) {
11     // ok
12     let _: i32 = val.into();
13     let _: U = val.into();
14     let _ = U::from(val);
15 }
16
17 fn test_questionmark() -> Result<(), ()> {
18     {
19         let _: i32 = 0i32.into();
20         Ok(Ok(()))
21     }??;
22     Ok(())
23 }
24
25 fn test_issue_3913() -> Result<(), std::io::Error> {
26     use std::fs;
27     use std::path::Path;
28
29     let path = Path::new(".");
30     for _ in fs::read_dir(path)? {}
31
32     Ok(())
33 }
34
35 fn main() {
36     test_generic(10i32);
37     test_generic2::<i32, i32>(10i32);
38     test_questionmark().unwrap();
39     test_issue_3913().unwrap();
40
41     let _: String = "foo".into();
42     let _: String = From::from("foo");
43     let _ = String::from("foo");
44     #[allow(clippy::identity_conversion)]
45     {
46         let _: String = "foo".into();
47         let _ = String::from("foo");
48         let _ = "".lines().into_iter();
49     }
50
51     let _: String = "foo".to_string().into();
52     let _: String = From::from("foo".to_string());
53     let _ = String::from("foo".to_string());
54     let _ = String::from(format!("A: {:04}", 123));
55     let _ = "".lines().into_iter();
56     let _ = vec![1, 2, 3].into_iter().into_iter();
57     let _: String = format!("Hello {}", "world").into();
58 }