3 #![warn(nonminimal_bool, logic_bug)]
5 #[allow(unused, many_single_char_names)]
7 let a: bool = unimplemented!();
8 let b: bool = unimplemented!();
9 let c: bool = unimplemented!();
10 let d: bool = unimplemented!();
11 let e: bool = unimplemented!();
20 let _ = cfg!(you_shall_not_not_pass) && a;
21 let _ = a || !b || !c || !d || !e;
22 let _ = !(a && b || c);
26 #[allow(unused, many_single_char_names)]
28 let a: i32 = unimplemented!();
29 let b: i32 = unimplemented!();
30 let c: i32 = unimplemented!();
31 let d: i32 = unimplemented!();
32 let e: i32 = unimplemented!();
33 let _ = a == b && a != b;
34 let _ = a == b && c == 5 && a == b;
35 let _ = a == b && c == 5 && b == a;
36 let _ = a < b && a >= b;
37 let _ = a > b && a <= b;
38 let _ = a > b && a == b;
39 let _ = a != b || !(a != b || c == d);
42 #[allow(unused, many_single_char_names)]
43 fn methods_with_negation() {
44 let a: Option<i32> = unimplemented!();
45 let b: Result<i32, i32> = unimplemented!();
55 let _ = !(a.is_some() && !c);
56 let _ = !(!c ^ c) || !a.is_some();
57 let _ = (!c ^ c) || !a.is_some();
58 let _ = !c ^ c || !a.is_some();
61 // Simplified versions of https://github.com/rust-lang-nursery/rust-clippy/issues/2638
62 // nonminimal_bool should only check the built-in Result and Some type, not
63 // any other types like the following.
64 enum CustomResultOk<E> { Ok, Err(E) }
65 enum CustomResultErr<E> { Ok, Err(E) }
66 enum CustomSomeSome<T> { Some(T), None }
67 enum CustomSomeNone<T> { Some(T), None }
69 impl<E> CustomResultOk<E> {
70 pub fn is_ok(&self) -> bool { true }
73 impl<E> CustomResultErr<E> {
74 pub fn is_err(&self) -> bool { true }
77 impl<T> CustomSomeSome<T> {
78 pub fn is_some(&self) -> bool { true }
81 impl<T> CustomSomeNone<T> {
82 pub fn is_none(&self) -> bool { true }
85 fn dont_warn_for_custom_methods_with_negation() {
86 let res = CustomResultOk::Err("Error");
87 // Should not warn and suggest 'is_err()' because the type does not
88 // implement is_err().
91 let res = CustomResultErr::Err("Error");
92 // Should not warn and suggest 'is_ok()' because the type does not
96 let res = CustomSomeSome::Some("thing");
97 // Should not warn and suggest 'is_none()' because the type does not
98 // implement is_none().
101 let res = CustomSomeNone::Some("thing");
102 // Should not warn and suggest 'is_some()' because the type does not
103 // implement is_some().
104 if !res.is_none() { }
107 // Only Built-in Result and Some types should suggest the negated alternative
108 fn warn_for_built_in_methods_with_negation() {
109 let res: Result<usize, usize> = Ok(1);
114 if !res.is_some() { }
115 if !res.is_none() { }
118 #[allow(neg_cmp_op_on_partial_ord)]
119 fn dont_warn_for_negated_partial_ord_comparison() {
120 let a: f64 = unimplemented!();
121 let b: f64 = unimplemented!();