]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/tests/ui/block_in_if_condition.rs
Auto merge of #71751 - oli-obk:const_ice, r=RalfJung
[rust.git] / src / tools / clippy / tests / ui / block_in_if_condition.rs
1 // run-rustfix
2 #![warn(clippy::block_in_if_condition_expr)]
3 #![warn(clippy::block_in_if_condition_stmt)]
4 #![allow(unused, clippy::let_and_return)]
5 #![warn(clippy::nonminimal_bool)]
6
7 macro_rules! blocky {
8     () => {{
9         true
10     }};
11 }
12
13 macro_rules! blocky_too {
14     () => {{
15         let r = true;
16         r
17     }};
18 }
19
20 fn macro_if() {
21     if blocky!() {}
22
23     if blocky_too!() {}
24 }
25
26 fn condition_has_block() -> i32 {
27     if {
28         let x = 3;
29         x == 3
30     } {
31         6
32     } else {
33         10
34     }
35 }
36
37 fn condition_has_block_with_single_expression() -> i32 {
38     if { true } {
39         6
40     } else {
41         10
42     }
43 }
44
45 fn condition_is_normal() -> i32 {
46     let x = 3;
47     if true && x == 3 {
48         6
49     } else {
50         10
51     }
52 }
53
54 fn condition_is_unsafe_block() {
55     let a: i32 = 1;
56
57     // this should not warn because the condition is an unsafe block
58     if unsafe { 1u32 == std::mem::transmute(a) } {
59         println!("1u32 == a");
60     }
61 }
62
63 fn block_in_assert() {
64     let opt = Some(42);
65     assert!(opt
66         .as_ref()
67         .and_then(|val| {
68             let mut v = val * 2;
69             v -= 1;
70             Some(v * 3)
71         })
72         .is_some());
73 }
74
75 fn main() {}