]> git.lizzy.rs Git - rust.git/blob - tests/ui/block_in_if_condition.rs
Adapt the *.stderr files of the ui-tests to the tool_lints
[rust.git] / tests / ui / block_in_if_condition.rs
1 #![feature(tool_lints)]
2
3
4 #![warn(clippy::block_in_if_condition_expr)]
5 #![warn(clippy::block_in_if_condition_stmt)]
6 #![allow(unused, clippy::let_and_return)]
7 #![warn(clippy::nonminimal_bool)]
8
9
10 macro_rules! blocky {
11     () => {{true}}
12 }
13
14 macro_rules! blocky_too {
15     () => {{
16         let r = true;
17         r
18     }}
19 }
20
21 fn macro_if() {
22     if blocky!() {
23     }
24
25     if blocky_too!() {
26     }
27 }
28
29 fn condition_has_block() -> i32 {
30     if {
31         let x = 3;
32         x == 3
33     } {
34         6
35     } else {
36         10
37     }
38 }
39
40 fn condition_has_block_with_single_expression() -> i32 {
41     if { true } {
42         6
43     } else {
44         10
45     }
46 }
47
48 fn predicate<F: FnOnce(T) -> bool, T>(pfn: F, val:T) -> bool {
49     pfn(val)
50 }
51
52 fn pred_test() {
53     let v = 3;
54     let sky = "blue";
55     // this is a sneaky case, where the block isn't directly in the condition, but is actually
56     // inside a closure that the condition is using.  same principle applies.  add some extra
57     // expressions to make sure linter isn't confused by them.
58     if v == 3 && sky == "blue" && predicate(|x| { let target = 3; x == target }, v) {
59     }
60
61     if predicate(|x| { let target = 3; x == target }, v) {
62     }
63 }
64
65 fn condition_is_normal() -> i32 {
66     let x = 3;
67     if true && x == 3 {
68         6
69     } else {
70         10
71     }
72 }
73
74 fn closure_without_block() {
75     if predicate(|x| x == 3, 6) {
76
77     }
78 }
79
80 fn condition_is_unsafe_block() {
81     let a: i32 = 1;
82
83     // this should not warn because the condition is an unsafe block
84     if unsafe { 1u32 == std::mem::transmute(a) } {
85         println!("1u32 == a");
86     }
87 }
88
89 fn main() {
90 }