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