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.
11 #![warn(clippy::needless_bool)]
15 macro_rules! bool_comparison_trigger {
16 ($($i:ident: $def:expr, $stb:expr );+ $(;)*) => (
20 $($i: (Cell<bool>, bool, bool)),+
25 pub fn trigger(&self, key: &str) -> bool {
27 if let stringify!($i) = key {
28 return self.$i.1 && self.$i.2 == $def;
37 #[allow(clippy::if_same_then_else)]
41 if x { true } else { true };
42 if x { false } else { false };
43 if x { true } else { false };
44 if x { false } else { true };
45 if x && y { false } else { true };
46 if x { x } else { false }; // would also be questionable, but we don't catch this yet
58 #[allow(clippy::if_same_then_else, clippy::needless_return)]
59 fn bool_ret(x: bool) -> bool {
60 if x { return true } else { return true };
63 #[allow(clippy::if_same_then_else, clippy::needless_return)]
64 fn bool_ret2(x: bool) -> bool {
65 if x { return false } else { return false };
68 #[allow(clippy::needless_return)]
69 fn bool_ret3(x: bool) -> bool {
70 if x { return true } else { return false };
73 #[allow(clippy::needless_return)]
74 fn bool_ret5(x: bool, y: bool) -> bool {
75 if x && y { return true } else { return false };
78 #[allow(clippy::needless_return)]
79 fn bool_ret4(x: bool) -> bool {
80 if x { return false } else { return true };
83 #[allow(clippy::needless_return)]
84 fn bool_ret6(x: bool, y: bool) -> bool {
85 if x && y { return false } else { return true };
88 fn needless_bool(x: bool) {
92 fn needless_bool2(x: bool) {
96 fn needless_bool3(x: bool) {
98 bool_comparison_trigger! {
99 test_one: false, false;
100 test_three: false, false;
101 test_two: true, true;