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