1 #![allow(unused, clippy::many_single_char_names, clippy::diverging_sub_expression)]
2 #![warn(clippy::nonminimal_bool)]
4 fn methods_with_negation() {
5 let a: Option<i32> = unimplemented!();
6 let b: Result<i32, i32> = unimplemented!();
16 let _ = !(a.is_some() && !c);
17 let _ = !(a.is_some() || !c);
18 let _ = !(!c ^ c) || !a.is_some();
19 let _ = (!c ^ c) || !a.is_some();
20 let _ = !c ^ c || !a.is_some();
23 // Simplified versions of https://github.com/rust-lang/rust-clippy/issues/2638
24 // clippy::nonminimal_bool should only check the built-in Result and Some type, not
25 // any other types like the following.
26 enum CustomResultOk<E> {
30 enum CustomResultErr<E> {
34 enum CustomSomeSome<T> {
38 enum CustomSomeNone<T> {
43 impl<E> CustomResultOk<E> {
44 pub fn is_ok(&self) -> bool {
49 impl<E> CustomResultErr<E> {
50 pub fn is_err(&self) -> bool {
55 impl<T> CustomSomeSome<T> {
56 pub fn is_some(&self) -> bool {
61 impl<T> CustomSomeNone<T> {
62 pub fn is_none(&self) -> bool {
67 fn dont_warn_for_custom_methods_with_negation() {
68 let res = CustomResultOk::Err("Error");
69 // Should not warn and suggest 'is_err()' because the type does not
70 // implement is_err().
73 let res = CustomResultErr::Err("Error");
74 // Should not warn and suggest 'is_ok()' because the type does not
78 let res = CustomSomeSome::Some("thing");
79 // Should not warn and suggest 'is_none()' because the type does not
80 // implement is_none().
83 let res = CustomSomeNone::Some("thing");
84 // Should not warn and suggest 'is_some()' because the type does not
85 // implement is_some().
89 // Only Built-in Result and Some types should suggest the negated alternative
90 fn warn_for_built_in_methods_with_negation() {
91 let res: Result<usize, usize> = Ok(1);
100 #[allow(clippy::neg_cmp_op_on_partial_ord)]
101 fn dont_warn_for_negated_partial_ord_comparison() {
102 let a: f64 = unimplemented!();
103 let b: f64 = unimplemented!();