]> git.proxmox.com Git - rustc.git/blame - src/tools/clippy/tests/ui/blocks_in_if_conditions.rs
New upstream version 1.52.1+dfsg1
[rustc.git] / src / tools / clippy / tests / ui / blocks_in_if_conditions.rs
CommitLineData
f20569fa
XL
1// run-rustfix
2#![warn(clippy::blocks_in_if_conditions)]
3#![allow(unused, clippy::let_and_return)]
4#![warn(clippy::nonminimal_bool)]
5
6macro_rules! blocky {
7 () => {{ true }};
8}
9
10macro_rules! blocky_too {
11 () => {{
12 let r = true;
13 r
14 }};
15}
16
17fn macro_if() {
18 if blocky!() {}
19
20 if blocky_too!() {}
21}
22
23fn condition_has_block() -> i32 {
24 if {
25 let x = 3;
26 x == 3
27 } {
28 6
29 } else {
30 10
31 }
32}
33
34fn condition_has_block_with_single_expression() -> i32 {
35 if { true } { 6 } else { 10 }
36}
37
38fn condition_is_normal() -> i32 {
39 let x = 3;
40 if true && x == 3 { 6 } else { 10 }
41}
42
43fn 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
52fn 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
65fn main() {}