1 #![warn(clippy::nonminimal_bool, clippy::logic_bug)]
3 #[allow(unused, clippy::many_single_char_names)]
5 let a: bool = unimplemented!();
6 let b: bool = unimplemented!();
7 let c: bool = unimplemented!();
8 let d: bool = unimplemented!();
9 let e: bool = unimplemented!();
18 let _ = cfg!(you_shall_not_not_pass) && a;
19 let _ = a || !b || !c || !d || !e;
20 let _ = !(a && b || c);
24 #[allow(unused, clippy::many_single_char_names)]
26 let a: i32 = unimplemented!();
27 let b: i32 = unimplemented!();
28 let c: i32 = unimplemented!();
29 let d: i32 = unimplemented!();
30 let e: i32 = unimplemented!();
31 let _ = a == b && a != b;
32 let _ = a == b && c == 5 && a == b;
33 let _ = a == b && c == 5 && b == a;
34 let _ = a < b && a >= b;
35 let _ = a > b && a <= b;
36 let _ = a > b && a == b;
37 let _ = a != b || !(a != b || c == d);
40 #[allow(unused, clippy::many_single_char_names)]
41 fn methods_with_negation() {
42 let a: Option<i32> = unimplemented!();
43 let b: Result<i32, i32> = unimplemented!();
53 let _ = !(a.is_some() && !c);
54 let _ = !(!c ^ c) || !a.is_some();
55 let _ = (!c ^ c) || !a.is_some();
56 let _ = !c ^ c || !a.is_some();
59 // Simplified versions of https://github.com/rust-lang/rust-clippy/issues/2638
60 // clippy::nonminimal_bool should only check the built-in Result and Some type, not
61 // any other types like the following.
62 enum CustomResultOk<E> {
66 enum CustomResultErr<E> {
70 enum CustomSomeSome<T> {
74 enum CustomSomeNone<T> {
79 impl<E> CustomResultOk<E> {
80 pub fn is_ok(&self) -> bool {
85 impl<E> CustomResultErr<E> {
86 pub fn is_err(&self) -> bool {
91 impl<T> CustomSomeSome<T> {
92 pub fn is_some(&self) -> bool {
97 impl<T> CustomSomeNone<T> {
98 pub fn is_none(&self) -> bool {
103 fn dont_warn_for_custom_methods_with_negation() {
104 let res = CustomResultOk::Err("Error");
105 // Should not warn and suggest 'is_err()' because the type does not
106 // implement is_err().
109 let res = CustomResultErr::Err("Error");
110 // Should not warn and suggest 'is_ok()' because the type does not
111 // implement is_ok().
114 let res = CustomSomeSome::Some("thing");
115 // Should not warn and suggest 'is_none()' because the type does not
116 // implement is_none().
119 let res = CustomSomeNone::Some("thing");
120 // Should not warn and suggest 'is_some()' because the type does not
121 // implement is_some().
125 // Only Built-in Result and Some types should suggest the negated alternative
126 fn warn_for_built_in_methods_with_negation() {
127 let res: Result<usize, usize> = Ok(1);
136 #[allow(clippy::neg_cmp_op_on_partial_ord)]
137 fn dont_warn_for_negated_partial_ord_comparison() {
138 let a: f64 = unimplemented!();
139 let b: f64 = unimplemented!();