3 #![warn(clippy::needless_question_mark)]
5 clippy::needless_return,
6 clippy::unnecessary_unwrap,
7 clippy::upper_case_acronyms,
11 #![feature(custom_inner_attributes)]
18 magic: Result<usize, bool>,
21 fn simple_option_bad1(to: TO) -> Option<usize> {
22 // return as a statement
23 return Some(to.magic?);
26 // formatting will add a semi-colon, which would make
27 // this identical to the test case above
29 fn simple_option_bad2(to: TO) -> Option<usize> {
30 // return as an expression
31 return Some(to.magic?)
34 fn simple_option_bad3(to: TO) -> Option<usize> {
35 // block value "return"
39 fn simple_option_bad4(to: Option<TO>) -> Option<usize> {
40 // single line closure
41 to.and_then(|t| Some(t.magic?))
44 // formatting this will remove the block brackets, making
45 // this test identical to the one above
47 fn simple_option_bad5(to: Option<TO>) -> Option<usize> {
54 fn simple_result_bad1(tr: TR) -> Result<usize, bool> {
58 // formatting will add a semi-colon, which would make
59 // this identical to the test case above
61 fn simple_result_bad2(tr: TR) -> Result<usize, bool> {
65 fn simple_result_bad3(tr: TR) -> Result<usize, bool> {
69 fn simple_result_bad4(tr: Result<TR, bool>) -> Result<usize, bool> {
70 tr.and_then(|t| Ok(t.magic?))
73 // formatting this will remove the block brackets, making
74 // this test identical to the one above
76 fn simple_result_bad5(tr: Result<TR, bool>) -> Result<usize, bool> {
82 fn also_bad(tr: Result<TR, bool>) -> Result<usize, bool> {
90 fn false_positive_test<U, T>(x: Result<(), U>) -> Result<(), T>
99 mod question_mark_none {
100 #![clippy::msrv = "1.12.0"]
101 fn needless_question_mark_option() -> Option<usize> {
103 magic: Option<usize>,
105 let to = TO { magic: None };
106 Some(to.magic?) // should not be triggered
109 fn needless_question_mark_result() -> Result<usize, bool> {
111 magic: Result<usize, bool>,
113 let to = TO { magic: Ok(1_usize) };
114 Ok(to.magic?) // should not be triggered
118 needless_question_mark_option();
119 needless_question_mark_result();
123 mod question_mark_result {
124 #![clippy::msrv = "1.21.0"]
125 fn needless_question_mark_option() -> Option<usize> {
127 magic: Option<usize>,
129 let to = TO { magic: None };
130 Some(to.magic?) // should not be triggered
133 fn needless_question_mark_result() -> Result<usize, bool> {
135 magic: Result<usize, bool>,
137 let to = TO { magic: Ok(1_usize) };
138 Ok(to.magic?) // should be triggered
142 needless_question_mark_option();
143 needless_question_mark_result();
147 mod question_mark_both {
148 #![clippy::msrv = "1.22.0"]
149 fn needless_question_mark_option() -> Option<usize> {
151 magic: Option<usize>,
153 let to = TO { magic: None };
154 Some(to.magic?) // should be triggered
157 fn needless_question_mark_result() -> Result<usize, bool> {
159 magic: Result<usize, bool>,
161 let to = TO { magic: Ok(1_usize) };
162 Ok(to.magic?) // should be triggered
166 needless_question_mark_option();
167 needless_question_mark_result();