]> git.lizzy.rs Git - rust.git/blob - tests/ui/identity_conversion.rs
Adapt the *.stderr files of the ui-tests to the tool_lints
[rust.git] / tests / ui / identity_conversion.rs
1 #![feature(tool_lints)]
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 main() {
26     test_generic(10i32);
27     test_generic2::<i32, i32>(10i32);
28     test_questionmark().unwrap();
29
30     let _: String = "foo".into();
31     let _: String = From::from("foo");
32     let _ = String::from("foo");
33     #[allow(clippy::identity_conversion)]
34     {
35         let _: String = "foo".into();
36         let _ = String::from("foo");
37         let _ = "".lines().into_iter();
38     }
39
40     let _: String = "foo".to_string().into();
41     let _: String = From::from("foo".to_string());
42     let _ = String::from("foo".to_string());
43     let _ = String::from(format!("A: {:04}", 123));
44     let _ = "".lines().into_iter();
45     let _ = vec![1, 2, 3].into_iter().into_iter();
46 }