]> git.lizzy.rs Git - rust.git/blob - tests/ui/blocks_in_if_conditions.rs
Add version = "Two" to rustfmt.toml
[rust.git] / tests / ui / blocks_in_if_conditions.rs
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     () => {{ true }};
8 }
9
10 macro_rules! blocky_too {
11     () => {{
12         let r = true;
13         r
14     }};
15 }
16
17 fn macro_if() {
18     if blocky!() {}
19
20     if blocky_too!() {}
21 }
22
23 fn condition_has_block() -> i32 {
24     if {
25         let x = 3;
26         x == 3
27     } {
28         6
29     } else {
30         10
31     }
32 }
33
34 fn condition_has_block_with_single_expression() -> i32 {
35     if { true } { 6 } else { 10 }
36 }
37
38 fn condition_is_normal() -> i32 {
39     let x = 3;
40     if true && x == 3 { 6 } else { 10 }
41 }
42
43 fn condition_is_unsafe_block() {
44     let a: i32 = 1;
45
46     // this should not warn because the condition is an unsafe block
47     if unsafe { 1u32 == std::mem::transmute(a) } {
48         println!("1u32 == a");
49     }
50 }
51
52 fn block_in_assert() {
53     let opt = Some(42);
54     assert!(
55         opt.as_ref()
56             .map(|val| {
57                 let mut v = val * 2;
58                 v -= 1;
59                 v * 3
60             })
61             .is_some()
62     );
63 }
64
65 fn main() {}