]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/tests/ui/useless_conversion.fixed
813cdaecaa91a8864f8f285a8f3c3130c0cb5bc4
[rust.git] / src / tools / clippy / tests / ui / useless_conversion.fixed
1 // run-rustfix
2
3 #![deny(clippy::useless_conversion)]
4
5 fn test_generic<T: Copy>(val: T) -> T {
6     let _ = val;
7     val
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;
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 test_issue_5833() -> Result<(), ()> {
36     let text = "foo\r\nbar\n\nbaz\n";
37     let lines = text.lines();
38     if Some("ok") == lines.into_iter().next() {}
39
40     Ok(())
41 }
42
43 fn main() {
44     test_generic(10i32);
45     test_generic2::<i32, i32>(10i32);
46     test_questionmark().unwrap();
47     test_issue_3913().unwrap();
48     test_issue_5833().unwrap();
49
50     let _: String = "foo".into();
51     let _: String = From::from("foo");
52     let _ = String::from("foo");
53     #[allow(clippy::useless_conversion)]
54     {
55         let _: String = "foo".into();
56         let _ = String::from("foo");
57         let _ = "".lines().into_iter();
58     }
59
60     let _: String = "foo".to_string();
61     let _: String = "foo".to_string();
62     let _ = "foo".to_string();
63     let _ = format!("A: {:04}", 123);
64     let _ = "".lines();
65     let _ = vec![1, 2, 3].into_iter();
66     let _: String = format!("Hello {}", "world");
67 }