1 // Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution.
4 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7 // option. This file may not be copied, modified, or distributed
8 // except according to those terms.
10 #![warn(clippy::nonminimal_bool, clippy::logic_bug)]
12 #[allow(unused, clippy::many_single_char_names)]
14 let a: bool = unimplemented!();
15 let b: bool = unimplemented!();
16 let c: bool = unimplemented!();
17 let d: bool = unimplemented!();
18 let e: bool = unimplemented!();
27 let _ = cfg!(you_shall_not_not_pass) && a;
28 let _ = a || !b || !c || !d || !e;
29 let _ = !(a && b || c);
33 #[allow(unused, clippy::many_single_char_names)]
35 let a: i32 = unimplemented!();
36 let b: i32 = unimplemented!();
37 let c: i32 = unimplemented!();
38 let d: i32 = unimplemented!();
39 let e: i32 = unimplemented!();
40 let _ = a == b && a != b;
41 let _ = a == b && c == 5 && a == b;
42 let _ = a == b && c == 5 && b == a;
43 let _ = a < b && a >= b;
44 let _ = a > b && a <= b;
45 let _ = a > b && a == b;
46 let _ = a != b || !(a != b || c == d);
49 #[allow(unused, clippy::many_single_char_names)]
50 fn methods_with_negation() {
51 let a: Option<i32> = unimplemented!();
52 let b: Result<i32, i32> = unimplemented!();
62 let _ = !(a.is_some() && !c);
63 let _ = !(!c ^ c) || !a.is_some();
64 let _ = (!c ^ c) || !a.is_some();
65 let _ = !c ^ c || !a.is_some();
68 // Simplified versions of https://github.com/rust-lang/rust-clippy/issues/2638
69 // clippy::nonminimal_bool should only check the built-in Result and Some type, not
70 // any other types like the following.
71 enum CustomResultOk<E> {
75 enum CustomResultErr<E> {
79 enum CustomSomeSome<T> {
83 enum CustomSomeNone<T> {
88 impl<E> CustomResultOk<E> {
89 pub fn is_ok(&self) -> bool {
94 impl<E> CustomResultErr<E> {
95 pub fn is_err(&self) -> bool {
100 impl<T> CustomSomeSome<T> {
101 pub fn is_some(&self) -> bool {
106 impl<T> CustomSomeNone<T> {
107 pub fn is_none(&self) -> bool {
112 fn dont_warn_for_custom_methods_with_negation() {
113 let res = CustomResultOk::Err("Error");
114 // Should not warn and suggest 'is_err()' because the type does not
115 // implement is_err().
118 let res = CustomResultErr::Err("Error");
119 // Should not warn and suggest 'is_ok()' because the type does not
120 // implement is_ok().
123 let res = CustomSomeSome::Some("thing");
124 // Should not warn and suggest 'is_none()' because the type does not
125 // implement is_none().
128 let res = CustomSomeNone::Some("thing");
129 // Should not warn and suggest 'is_some()' because the type does not
130 // implement is_some().
134 // Only Built-in Result and Some types should suggest the negated alternative
135 fn warn_for_built_in_methods_with_negation() {
136 let res: Result<usize, usize> = Ok(1);
145 #[allow(clippy::neg_cmp_op_on_partial_ord)]
146 fn dont_warn_for_negated_partial_ord_comparison() {
147 let a: f64 = unimplemented!();
148 let b: f64 = unimplemented!();