Skip to content

Commit 7c9e192

Browse files
committed
Test for empty blocks and update from master
1 parent 8c0b4d7 commit 7c9e192

File tree

2 files changed

+39
-28
lines changed

2 files changed

+39
-28
lines changed

tests/ui/shared_code_in_if_blocks/valid_if_blocks.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,11 @@ fn valid_examples() {
9999
let x = 2;
100100
println!("{}", x);
101101
}
102+
103+
// Let's test empty blocks
104+
if false {
105+
} else {
106+
}
102107
}
103108

104109
/// This makes sure that the `if_same_then_else` masks the `shared_code_in_if_blocks` lint
@@ -128,20 +133,12 @@ fn trigger_other_lint() {
128133
println!("I'm a doppelgänger");
129134
// Don't listen to my clone below
130135

131-
if y == 90 {
132-
"=^.^="
133-
} else {
134-
":D"
135-
}
136+
if y == 90 { "=^.^=" } else { ":D" }
136137
} else {
137138
// Don't listen to my clone above
138139
println!("I'm a doppelgänger");
139140

140-
if y == 90 {
141-
"=^.^="
142-
} else {
143-
":D"
144-
}
141+
if y == 90 { "=^.^=" } else { ":D" }
145142
};
146143

147144
if x == 0 {
Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
error: this `if` has identical blocks
2-
--> $DIR/valid_if_blocks.rs:110:15
2+
--> $DIR/valid_if_blocks.rs:104:14
33
|
4-
LL | if x == 0 {
5-
| _______________^
6-
LL | | let u = 19;
7-
LL | | println!("How are u today?");
8-
LL | | let _ = "This is a string";
4+
LL | if false {
5+
| ______________^
96
LL | | } else {
107
| |_____^
118
|
@@ -15,7 +12,26 @@ note: the lint level is defined here
1512
LL | #![deny(clippy::if_same_then_else, clippy::shared_code_in_if_blocks)]
1613
| ^^^^^^^^^^^^^^^^^^^^^^^^^
1714
note: same as this
18-
--> $DIR/valid_if_blocks.rs:114:12
15+
--> $DIR/valid_if_blocks.rs:105:12
16+
|
17+
LL | } else {
18+
| ____________^
19+
LL | | }
20+
| |_____^
21+
22+
error: this `if` has identical blocks
23+
--> $DIR/valid_if_blocks.rs:115:15
24+
|
25+
LL | if x == 0 {
26+
| _______________^
27+
LL | | let u = 19;
28+
LL | | println!("How are u today?");
29+
LL | | let _ = "This is a string";
30+
LL | | } else {
31+
| |_____^
32+
|
33+
note: same as this
34+
--> $DIR/valid_if_blocks.rs:119:12
1935
|
2036
LL | } else {
2137
| ____________^
@@ -26,45 +42,43 @@ LL | | }
2642
| |_____^
2743

2844
error: this `if` has identical blocks
29-
--> $DIR/valid_if_blocks.rs:121:23
45+
--> $DIR/valid_if_blocks.rs:126:23
3046
|
3147
LL | let _ = if x == 6 { 7 } else { 7 };
3248
| ^^^^^
3349
|
3450
note: same as this
35-
--> $DIR/valid_if_blocks.rs:121:34
51+
--> $DIR/valid_if_blocks.rs:126:34
3652
|
3753
LL | let _ = if x == 6 { 7 } else { 7 };
3854
| ^^^^^
3955

4056
error: this `if` has identical blocks
41-
--> $DIR/valid_if_blocks.rs:127:23
57+
--> $DIR/valid_if_blocks.rs:132:23
4258
|
4359
LL | } else if x == 68 {
4460
| _______________________^
4561
LL | | println!("I'm a doppelgänger");
4662
LL | | // Don't listen to my clone below
4763
LL | |
48-
... |
49-
LL | | }
64+
LL | | if y == 90 { "=^.^=" } else { ":D" }
5065
LL | | } else {
5166
| |_____^
5267
|
5368
note: same as this
54-
--> $DIR/valid_if_blocks.rs:136:12
69+
--> $DIR/valid_if_blocks.rs:137:12
5570
|
5671
LL | } else {
5772
| ____________^
5873
LL | | // Don't listen to my clone above
5974
LL | | println!("I'm a doppelgänger");
6075
LL | |
61-
... |
62-
LL | | }
76+
LL | | if y == 90 { "=^.^=" } else { ":D" }
6377
LL | | };
6478
| |_____^
6579

6680
error: this `if` has identical blocks
67-
--> $DIR/valid_if_blocks.rs:149:23
81+
--> $DIR/valid_if_blocks.rs:146:23
6882
|
6983
LL | } else if x == 68 {
7084
| _______________________^
@@ -74,7 +88,7 @@ LL | | } else {
7488
| |_____^
7589
|
7690
note: same as this
77-
--> $DIR/valid_if_blocks.rs:152:12
91+
--> $DIR/valid_if_blocks.rs:149:12
7892
|
7993
LL | } else {
8094
| ____________^
@@ -83,5 +97,5 @@ LL | | println!("I'm a doppelgänger");
8397
LL | | }
8498
| |_____^
8599

86-
error: aborting due to 4 previous errors
100+
error: aborting due to 5 previous errors
87101

0 commit comments

Comments
 (0)