2 #![allow(unused, clippy::diverging_sub_expression)]
3 #![warn(clippy::nonminimal_bool)]
5 fn methods_with_negation() {
6 let a: Option<i32> = unimplemented!();
7 let b: Result<i32, i32> = unimplemented!();
17 let _ = !(a.is_some() && !c);
18 let _ = !(a.is_some() || !c);
19 let _ = !(!c ^ c) || !a.is_some();
20 let _ = (!c ^ c) || !a.is_some();
21 let _ = !c ^ c || !a.is_some();
24 // Simplified versions of https://github.com/rust-lang/rust-clippy/issues/2638
25 // clippy::nonminimal_bool should only check the built-in Result and Some type, not
26 // any other types like the following.
27 enum CustomResultOk<E> {
31 enum CustomResultErr<E> {
35 enum CustomSomeSome<T> {
39 enum CustomSomeNone<T> {
44 impl<E> CustomResultOk<E> {
45 pub fn is_ok(&self) -> bool {
50 impl<E> CustomResultErr<E> {
51 pub fn is_err(&self) -> bool {
56 impl<T> CustomSomeSome<T> {
57 pub fn is_some(&self) -> bool {
62 impl<T> CustomSomeNone<T> {
63 pub fn is_none(&self) -> bool {
68 fn dont_warn_for_custom_methods_with_negation() {
69 let res = CustomResultOk::Err("Error");
70 // Should not warn and suggest 'is_err()' because the type does not
71 // implement is_err().
74 let res = CustomResultErr::Err("Error");
75 // Should not warn and suggest 'is_ok()' because the type does not
79 let res = CustomSomeSome::Some("thing");
80 // Should not warn and suggest 'is_none()' because the type does not
81 // implement is_none().
84 let res = CustomSomeNone::Some("thing");
85 // Should not warn and suggest 'is_some()' because the type does not
86 // implement is_some().
90 // Only Built-in Result and Some types should suggest the negated alternative
91 fn warn_for_built_in_methods_with_negation() {
92 let res: Result<usize, usize> = Ok(1);
101 #[allow(clippy::neg_cmp_op_on_partial_ord)]
102 fn dont_warn_for_negated_partial_ord_comparison() {
103 let a: f64 = unimplemented!();
104 let b: f64 = unimplemented!();