1 #![allow(dead_code, clippy::eval_order_dependence)]
2 #![deny(clippy::if_same_then_else, clippy::branches_sharing_code)]
4 // This tests valid if blocks that shouldn't trigger the lint
6 // Tests with value references are includes in "shared_code_at_bottom.rs"
11 // The edge statements are different
15 println!("This is the same: vvv");
17 println!("The block expression is different");
19 println!("Different end 1");
23 println!("This is the same: vvv");
25 println!("The block expression is different");
27 println!("Different end 2");
32 println!("Hello world!");
33 println!("Hello back, how are you?");
35 // This is different vvvv
36 println!("Howdy stranger =^.^=");
38 println!("Bye Bye World");
40 println!("Hello world!");
41 println!("Hello back, how are you?");
43 // This is different vvvv
44 println!("Hello reviewer :D");
46 println!("Bye Bye World");
49 // Overlapping statements only in else if blocks -> Don't lint
51 println!("I'm important!")
53 println!("I share code in else if");
57 println!("I share code in else if");
59 println!("x is nether x nor 17");
62 // Mutability is different
65 println!("Value y is: {}", y);
70 println!("Value y is: {}", y);
74 // Same blocks but at start and bottom so no `if_same_then_else` lint
79 // Don't tell the programmer, my code is also in the else block
81 println!("+-----------+");
85 println!("| \\_____/ |");
87 println!("+-----------+");
92 // I'm so much better than the x == 418 block. Trust me
103 // Let's test empty blocks
109 /// This makes sure that the `if_same_then_else` masks the `shared_code_in_if_blocks` lint
110 fn trigger_other_lint() {
117 println!("How are u today?");
118 let _ = "This is a string";
121 println!("How are u today?");
122 let _ = "This is a string";
125 // Only same expression
126 let _ = if x == 6 { 7 } else { 7 };
128 // Same in else if block
130 println!("Well I'm the most important block");
131 "I'm a pretty string"
133 println!("I'm a doppelgänger");
134 // Don't listen to my clone below
136 if y == 90 { "=^.^=" } else { ":D" }
138 // Don't listen to my clone above
139 println!("I'm a doppelgänger");
141 if y == 90 { "=^.^=" } else { ":D" }
145 println!("I'm single");
147 println!("I'm a doppelgänger");
148 // Don't listen to my clone below
150 // Don't listen to my clone above
151 println!("I'm a doppelgänger");