Skip to content

Split up if_same_then_else ui test #5066

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
137 changes: 3 additions & 134 deletions tests/ui/if_same_then_else.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
#![warn(clippy::if_same_then_else)]
#![allow(
clippy::blacklisted_name,
clippy::collapsible_if,
clippy::cognitive_complexity,
clippy::eq_op,
clippy::needless_return,
clippy::never_loop,
clippy::no_effect,
clippy::zero_divided_by_zero,
clippy::unused_unit
clippy::unused_unit,
clippy::zero_divided_by_zero
)]

struct Foo {
Expand All @@ -19,7 +16,7 @@ fn foo() -> bool {
unimplemented!()
}

fn if_same_then_else() -> Result<&'static str, ()> {
fn if_same_then_else() {
if true {
Foo { bar: 42 };
0..10;
Expand Down Expand Up @@ -94,27 +91,6 @@ fn if_same_then_else() -> Result<&'static str, ()> {
42
};

if true {
for _ in &[42] {
let foo: &Option<_> = &Some::<u8>(42);
if true {
break;
} else {
continue;
}
}
} else {
//~ ERROR same body as `if` block
for _ in &[42] {
let foo: &Option<_> = &Some::<u8>(42);
if true {
break;
} else {
continue;
}
}
}

if true {
let bar = if true { 42 } else { 43 };

Expand Down Expand Up @@ -149,113 +125,6 @@ fn if_same_then_else() -> Result<&'static str, ()> {
_ => 4,
};
}

if true {
if let Some(a) = Some(42) {}
} else {
//~ ERROR same body as `if` block
if let Some(a) = Some(42) {}
}

if true {
if let (1, .., 3) = (1, 2, 3) {}
} else {
//~ ERROR same body as `if` block
if let (1, .., 3) = (1, 2, 3) {}
}

if true {
if let (1, .., 3) = (1, 2, 3) {}
} else {
if let (.., 3) = (1, 2, 3) {}
}

if true {
if let (1, .., 3) = (1, 2, 3) {}
} else {
if let (.., 4) = (1, 2, 3) {}
}

if true {
if let (1, .., 3) = (1, 2, 3) {}
} else {
if let (.., 1, 3) = (1, 2, 3) {}
}

if true {
if let Some(42) = None {}
} else {
if let Option::Some(42) = None {}
}

if true {
if let Some(42) = None::<u8> {}
} else {
if let Some(42) = None {}
}

if true {
if let Some(42) = None::<u8> {}
} else {
if let Some(42) = None::<u32> {}
}

if true {
if let Some(a) = Some(42) {}
} else {
if let Some(a) = Some(43) {}
}

// Same NaNs
let _ = if true {
std::f32::NAN
} else {
//~ ERROR same body as `if` block
std::f32::NAN
};

if true {
Ok("foo")?;
} else {
//~ ERROR same body as `if` block
Ok("foo")?;
}

if true {
let foo = "";
return Ok(&foo[0..]);
} else if false {
let foo = "bar";
return Ok(&foo[0..]);
} else {
let foo = "";
return Ok(&foo[0..]);
}

if true {
let foo = "";
return Ok(&foo[0..]);
} else if false {
let foo = "bar";
return Ok(&foo[0..]);
} else if true {
let foo = "";
return Ok(&foo[0..]);
} else {
let foo = "";
return Ok(&foo[0..]);
}

// False positive `if_same_then_else`: `let (x, y)` vs. `let (y, x)`; see issue #3559.
if true {
let foo = "";
let (x, y) = (1, 2);
return Ok(&foo[x..y]);
} else {
let foo = "";
let (y, x) = (1, 2);
return Ok(&foo[x..y]);
}
}

// Issue #2423. This was causing an ICE.
Expand Down
157 changes: 11 additions & 146 deletions tests/ui/if_same_then_else.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: this `if` has identical blocks
--> $DIR/if_same_then_else.rs:31:12
--> $DIR/if_same_then_else.rs:28:12
|
LL | } else {
| ____________^
Expand All @@ -13,7 +13,7 @@ LL | | }
|
= note: `-D clippy::if-same-then-else` implied by `-D warnings`
note: same as this
--> $DIR/if_same_then_else.rs:23:13
--> $DIR/if_same_then_else.rs:20:13
|
LL | if true {
| _____________^
Expand All @@ -26,7 +26,7 @@ LL | | } else {
| |_____^

error: this `if` has identical blocks
--> $DIR/if_same_then_else.rs:69:12
--> $DIR/if_same_then_else.rs:66:12
|
LL | } else {
| ____________^
Expand All @@ -36,7 +36,7 @@ LL | | };
| |_____^
|
note: same as this
--> $DIR/if_same_then_else.rs:67:21
--> $DIR/if_same_then_else.rs:64:21
|
LL | let _ = if true {
| _____________________^
Expand All @@ -45,7 +45,7 @@ LL | | } else {
| |_____^

error: this `if` has identical blocks
--> $DIR/if_same_then_else.rs:76:12
--> $DIR/if_same_then_else.rs:73:12
|
LL | } else {
| ____________^
Expand All @@ -55,7 +55,7 @@ LL | | };
| |_____^
|
note: same as this
--> $DIR/if_same_then_else.rs:74:21
--> $DIR/if_same_then_else.rs:71:21
|
LL | let _ = if true {
| _____________________^
Expand All @@ -64,7 +64,7 @@ LL | | } else {
| |_____^

error: this `if` has identical blocks
--> $DIR/if_same_then_else.rs:92:12
--> $DIR/if_same_then_else.rs:89:12
|
LL | } else {
| ____________^
Expand All @@ -74,7 +74,7 @@ LL | | };
| |_____^
|
note: same as this
--> $DIR/if_same_then_else.rs:90:21
--> $DIR/if_same_then_else.rs:87:21
|
LL | let _ = if true {
| _____________________^
Expand All @@ -83,33 +83,7 @@ LL | | } else {
| |_____^

error: this `if` has identical blocks
--> $DIR/if_same_then_else.rs:106:12
|
LL | } else {
| ____________^
LL | | //~ ERROR same body as `if` block
LL | | for _ in &[42] {
LL | | let foo: &Option<_> = &Some::<u8>(42);
... |
LL | | }
LL | | }
| |_____^
|
note: same as this
--> $DIR/if_same_then_else.rs:97:13
|
LL | if true {
| _____________^
LL | | for _ in &[42] {
LL | | let foo: &Option<_> = &Some::<u8>(42);
LL | | if true {
... |
LL | | }
LL | | } else {
| |_____^

error: this `if` has identical blocks
--> $DIR/if_same_then_else.rs:125:12
--> $DIR/if_same_then_else.rs:101:12
|
LL | } else {
| ____________^
Expand All @@ -122,7 +96,7 @@ LL | | }
| |_____^
|
note: same as this
--> $DIR/if_same_then_else.rs:118:13
--> $DIR/if_same_then_else.rs:94:13
|
LL | if true {
| _____________^
Expand All @@ -134,114 +108,5 @@ LL | | bar + 1;
LL | | } else {
| |_____^

error: this `if` has identical blocks
--> $DIR/if_same_then_else.rs:155:12
|
LL | } else {
| ____________^
LL | | //~ ERROR same body as `if` block
LL | | if let Some(a) = Some(42) {}
LL | | }
| |_____^
|
note: same as this
--> $DIR/if_same_then_else.rs:153:13
|
LL | if true {
| _____________^
LL | | if let Some(a) = Some(42) {}
LL | | } else {
| |_____^

error: this `if` has identical blocks
--> $DIR/if_same_then_else.rs:162:12
|
LL | } else {
| ____________^
LL | | //~ ERROR same body as `if` block
LL | | if let (1, .., 3) = (1, 2, 3) {}
LL | | }
| |_____^
|
note: same as this
--> $DIR/if_same_then_else.rs:160:13
|
LL | if true {
| _____________^
LL | | if let (1, .., 3) = (1, 2, 3) {}
LL | | } else {
| |_____^

error: this `if` has identical blocks
--> $DIR/if_same_then_else.rs:212:12
|
LL | } else {
| ____________^
LL | | //~ ERROR same body as `if` block
LL | | std::f32::NAN
LL | | };
| |_____^
|
note: same as this
--> $DIR/if_same_then_else.rs:210:21
|
LL | let _ = if true {
| _____________________^
LL | | std::f32::NAN
LL | | } else {
| |_____^

error: this `if` has identical blocks
--> $DIR/if_same_then_else.rs:219:12
|
LL | } else {
| ____________^
LL | | //~ ERROR same body as `if` block
LL | | Ok("foo")?;
LL | | }
| |_____^
|
note: same as this
--> $DIR/if_same_then_else.rs:217:13
|
LL | if true {
| _____________^
LL | | Ok("foo")?;
LL | | } else {
| |_____^

error: this `if` has identical blocks
--> $DIR/if_same_then_else.rs:244:12
|
LL | } else {
| ____________^
LL | | let foo = "";
LL | | return Ok(&foo[0..]);
LL | | }
| |_____^
|
note: same as this
--> $DIR/if_same_then_else.rs:241:20
|
LL | } else if true {
| ____________________^
LL | | let foo = "";
LL | | return Ok(&foo[0..]);
LL | | } else {
| |_____^

error: this `if` has the same condition as a previous `if`
--> $DIR/if_same_then_else.rs:241:15
|
LL | } else if true {
| ^^^^
|
= note: `#[deny(clippy::ifs_same_cond)]` on by default
note: same as this
--> $DIR/if_same_then_else.rs:235:8
|
LL | if true {
| ^^^^

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

Loading