]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/tests/ui/unnecessary_wraps.rs
Auto merge of #79780 - camelid:use-summary_opts, r=GuillaumeGomez
[rust.git] / src / tools / clippy / tests / ui / unnecessary_wraps.rs
1 #![warn(clippy::unnecessary_wraps)]
2 #![allow(clippy::no_effect)]
3 #![allow(clippy::needless_return)]
4 #![allow(clippy::if_same_then_else)]
5 #![allow(dead_code)]
6
7 // should be linted
8 fn func1(a: bool, b: bool) -> Option<i32> {
9     if a && b {
10         return Some(42);
11     }
12     if a {
13         Some(-1);
14         Some(2)
15     } else {
16         return Some(1337);
17     }
18 }
19
20 // should be linted
21 fn func2(a: bool, b: bool) -> Option<i32> {
22     if a && b {
23         return Some(10);
24     }
25     if a {
26         Some(20)
27     } else {
28         Some(30)
29     }
30 }
31
32 // public fns should not be linted
33 pub fn func3(a: bool) -> Option<i32> {
34     if a {
35         Some(1)
36     } else {
37         Some(1)
38     }
39 }
40
41 // should not be linted
42 fn func4(a: bool) -> Option<i32> {
43     if a {
44         Some(1)
45     } else {
46         None
47     }
48 }
49
50 // should be linted
51 fn func5() -> Option<i32> {
52     Some(1)
53 }
54
55 // should not be linted
56 fn func6() -> Option<i32> {
57     None
58 }
59
60 // should be linted
61 fn func7() -> Result<i32, ()> {
62     Ok(1)
63 }
64
65 // should not be linted
66 fn func8(a: bool) -> Result<i32, ()> {
67     if a {
68         Ok(1)
69     } else {
70         Err(())
71     }
72 }
73
74 // should not be linted
75 fn func9(a: bool) -> Result<i32, ()> {
76     Err(())
77 }
78
79 // should not be linted
80 fn func10() -> Option<()> {
81     unimplemented!()
82 }
83
84 struct A;
85
86 impl A {
87     // should not be linted
88     pub fn func11() -> Option<i32> {
89         Some(1)
90     }
91
92     // should be linted
93     fn func12() -> Option<i32> {
94         Some(1)
95     }
96 }
97
98 trait B {
99     // trait impls are not linted
100     fn func13() -> Option<i32> {
101         Some(1)
102     }
103 }
104
105 impl B for A {
106     // trait impls are not linted
107     fn func13() -> Option<i32> {
108         Some(0)
109     }
110 }
111
112 fn issue_6384(s: &str) -> Option<&str> {
113     Some(match s {
114         "a" => "A",
115         _ => return None,
116     })
117 }
118
119 fn main() {
120     // method calls are not linted
121     func1(true, true);
122     func2(true, true);
123 }