Skip to content

Commit

Permalink
Test for empty blocks and update from master
Browse files Browse the repository at this point in the history
  • Loading branch information
xFrednet committed Apr 1, 2021
1 parent e19e5c7 commit 128b71b
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 28 deletions.
17 changes: 7 additions & 10 deletions tests/ui/shared_code_in_if_blocks/valid_if_blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ fn valid_examples() {
let x = 2;
println!("{}", x);
}

// Let's test empty blocks
if false {
} else {
}
}

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

if y == 90 {
"=^.^="
} else {
":D"
}
if y == 90 { "=^.^=" } else { ":D" }
} else {
// Don't listen to my clone above
println!("I'm a doppelgänger");

if y == 90 {
"=^.^="
} else {
":D"
}
if y == 90 { "=^.^=" } else { ":D" }
};

if x == 0 {
Expand Down
50 changes: 32 additions & 18 deletions tests/ui/shared_code_in_if_blocks/valid_if_blocks.stderr
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
error: this `if` has identical blocks
--> $DIR/valid_if_blocks.rs:110:15
--> $DIR/valid_if_blocks.rs:104:14
|
LL | if x == 0 {
| _______________^
LL | | let u = 19;
LL | | println!("How are u today?");
LL | | let _ = "This is a string";
LL | if false {
| ______________^
LL | | } else {
| |_____^
|
Expand All @@ -15,7 +12,26 @@ note: the lint level is defined here
LL | #![deny(clippy::if_same_then_else, clippy::shared_code_in_if_blocks)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^
note: same as this
--> $DIR/valid_if_blocks.rs:114:12
--> $DIR/valid_if_blocks.rs:105:12
|
LL | } else {
| ____________^
LL | | }
| |_____^

error: this `if` has identical blocks
--> $DIR/valid_if_blocks.rs:115:15
|
LL | if x == 0 {
| _______________^
LL | | let u = 19;
LL | | println!("How are u today?");
LL | | let _ = "This is a string";
LL | | } else {
| |_____^
|
note: same as this
--> $DIR/valid_if_blocks.rs:119:12
|
LL | } else {
| ____________^
Expand All @@ -26,45 +42,43 @@ LL | | }
| |_____^

error: this `if` has identical blocks
--> $DIR/valid_if_blocks.rs:121:23
--> $DIR/valid_if_blocks.rs:126:23
|
LL | let _ = if x == 6 { 7 } else { 7 };
| ^^^^^
|
note: same as this
--> $DIR/valid_if_blocks.rs:121:34
--> $DIR/valid_if_blocks.rs:126:34
|
LL | let _ = if x == 6 { 7 } else { 7 };
| ^^^^^

error: this `if` has identical blocks
--> $DIR/valid_if_blocks.rs:127:23
--> $DIR/valid_if_blocks.rs:132:23
|
LL | } else if x == 68 {
| _______________________^
LL | | println!("I'm a doppelgänger");
LL | | // Don't listen to my clone below
LL | |
... |
LL | | }
LL | | if y == 90 { "=^.^=" } else { ":D" }
LL | | } else {
| |_____^
|
note: same as this
--> $DIR/valid_if_blocks.rs:136:12
--> $DIR/valid_if_blocks.rs:137:12
|
LL | } else {
| ____________^
LL | | // Don't listen to my clone above
LL | | println!("I'm a doppelgänger");
LL | |
... |
LL | | }
LL | | if y == 90 { "=^.^=" } else { ":D" }
LL | | };
| |_____^

error: this `if` has identical blocks
--> $DIR/valid_if_blocks.rs:149:23
--> $DIR/valid_if_blocks.rs:146:23
|
LL | } else if x == 68 {
| _______________________^
Expand All @@ -74,7 +88,7 @@ LL | | } else {
| |_____^
|
note: same as this
--> $DIR/valid_if_blocks.rs:152:12
--> $DIR/valid_if_blocks.rs:149:12
|
LL | } else {
| ____________^
Expand All @@ -83,5 +97,5 @@ LL | | println!("I'm a doppelgänger");
LL | | }
| |_____^

error: aborting due to 4 previous errors
error: aborting due to 5 previous errors

0 comments on commit 128b71b

Please sign in to comment.