1 #![allow(dead_code, clippy::eval_order_dependence)]
2 #![deny(clippy::if_same_then_else, clippy::shared_code_in_if_blocks)]
4 // This tests the shared_code_in_if_blocks lint at the start of blocks
6 // Tests with value references are includes in "shared_code_at_bot.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
96 /// This makes sure that the `if_same_then_else` masks the `shared_code_in_if_blocks` lint
97 fn trigger_other_lint() {
104 println!("How are u today?");
105 let _ = "This is a string";
108 println!("How are u today?");
109 let _ = "This is a string";
112 // More complex same blocks
118 let pet = Duck { num: 18 };
119 println!("{:?}", pet);
125 let pet = Duck { num: 18 };
126 println!("{:?}", pet);
129 // Only same expression
130 let _ = if x == 6 { 7 } else { 7 };
132 // Same in else if block
134 println!("Well I'm the most important block");
135 "I'm a pretty string"
137 println!("I'm a doppelgänger");
138 // Don't listen to my clone below
146 // Don't listen to my clone above
147 println!("I'm a doppelgänger");
157 println!("I'm single");
159 println!("I'm a doppelgänger");
160 // Don't listen to my clone below
162 // Don't listen to my clone above
163 println!("I'm a doppelgänger");