]> git.lizzy.rs Git - rust.git/blob - tests/ui/needless_bool.rs
Merge remote-tracking branch 'upstream/master'
[rust.git] / tests / ui / needless_bool.rs
1 // Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution.
3 //
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.
9
10
11
12
13 #![warn(clippy::needless_bool)]
14
15 #[allow(clippy::if_same_then_else)]
16 fn main() {
17     let x = true;
18     let y = false;
19     if x { true } else { true };
20     if x { false } else { false };
21     if x { true } else { false };
22     if x { false } else { true };
23     if x && y { false } else { true };
24     if x { x } else { false }; // would also be questionable, but we don't catch this yet
25     bool_ret(x);
26     bool_ret2(x);
27     bool_ret3(x);
28     bool_ret5(x, x);
29     bool_ret4(x);
30     bool_ret6(x, x);
31 }
32
33 #[allow(clippy::if_same_then_else, clippy::needless_return)]
34 fn bool_ret(x: bool) -> bool {
35     if x { return true } else { return true };
36 }
37
38 #[allow(clippy::if_same_then_else, clippy::needless_return)]
39 fn bool_ret2(x: bool) -> bool {
40     if x { return false } else { return false };
41 }
42
43 #[allow(clippy::needless_return)]
44 fn bool_ret3(x: bool) -> bool {
45     if x { return true } else { return false };
46 }
47
48 #[allow(clippy::needless_return)]
49 fn bool_ret5(x: bool, y: bool) -> bool {
50     if x && y { return true } else { return false };
51 }
52
53 #[allow(clippy::needless_return)]
54 fn bool_ret4(x: bool) -> bool {
55     if x { return false } else { return true };
56 }
57
58 #[allow(clippy::needless_return)]
59 fn bool_ret6(x: bool, y: bool) -> bool {
60     if x && y { return false } else { return true };
61 }