Skip to content

Commit 3de9a3d

Browse files
committed
Auto merge of #3612 - phansch:copies_cleanup, r=flip1995
UI test cleanup: Extract ifs_same_cond tests cc #2038
2 parents 51c77c1 + 3b03537 commit 3de9a3d

File tree

4 files changed

+86
-82
lines changed

4 files changed

+86
-82
lines changed

Diff for: tests/ui/copies.rs

-44
Original file line numberDiff line numberDiff line change
@@ -348,50 +348,6 @@ fn if_same_then_else() -> Result<&'static str, ()> {
348348
}
349349
}
350350

351-
#[warn(clippy::ifs_same_cond)]
352-
#[allow(clippy::if_same_then_else)] // all empty blocks
353-
fn ifs_same_cond() {
354-
let a = 0;
355-
let b = false;
356-
357-
if b {
358-
} else if b {
359-
//~ ERROR ifs same condition
360-
}
361-
362-
if a == 1 {
363-
} else if a == 1 {
364-
//~ ERROR ifs same condition
365-
}
366-
367-
if 2 * a == 1 {
368-
} else if 2 * a == 2 {
369-
} else if 2 * a == 1 {
370-
//~ ERROR ifs same condition
371-
} else if a == 1 {
372-
}
373-
374-
// See #659
375-
if cfg!(feature = "feature1-659") {
376-
1
377-
} else if cfg!(feature = "feature2-659") {
378-
2
379-
} else {
380-
3
381-
};
382-
383-
let mut v = vec![1];
384-
if v.pop() == None {
385-
// ok, functions
386-
} else if v.pop() == None {
387-
}
388-
389-
if v.len() == 42 {
390-
// ok, functions
391-
} else if v.len() == 42 {
392-
}
393-
}
394-
395351
fn main() {}
396352

397353
// Issue #2423. This was causing an ICE

Diff for: tests/ui/copies.stderr

+1-38
Original file line numberDiff line numberDiff line change
@@ -351,42 +351,5 @@ LL | | try!(Ok("foo"));
351351
LL | | } else {
352352
| |_____^
353353

354-
error: this `if` has the same condition as a previous if
355-
--> $DIR/copies.rs:358:15
356-
|
357-
LL | } else if b {
358-
| ^
359-
|
360-
= note: `-D clippy::ifs-same-cond` implied by `-D warnings`
361-
note: same as this
362-
--> $DIR/copies.rs:357:8
363-
|
364-
LL | if b {
365-
| ^
366-
367-
error: this `if` has the same condition as a previous if
368-
--> $DIR/copies.rs:363:15
369-
|
370-
LL | } else if a == 1 {
371-
| ^^^^^^
372-
|
373-
note: same as this
374-
--> $DIR/copies.rs:362:8
375-
|
376-
LL | if a == 1 {
377-
| ^^^^^^
378-
379-
error: this `if` has the same condition as a previous if
380-
--> $DIR/copies.rs:369:15
381-
|
382-
LL | } else if 2 * a == 1 {
383-
| ^^^^^^^^^^
384-
|
385-
note: same as this
386-
--> $DIR/copies.rs:367:8
387-
|
388-
LL | if 2 * a == 1 {
389-
| ^^^^^^^^^^
390-
391-
error: aborting due to 20 previous errors
354+
error: aborting due to 17 previous errors
392355

Diff for: tests/ui/ifs_same_cond.rs

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#![warn(clippy::ifs_same_cond)]
2+
#![allow(clippy::if_same_then_else)] // all empty blocks
3+
4+
fn ifs_same_cond() {
5+
let a = 0;
6+
let b = false;
7+
8+
if b {
9+
} else if b {
10+
//~ ERROR ifs same condition
11+
}
12+
13+
if a == 1 {
14+
} else if a == 1 {
15+
//~ ERROR ifs same condition
16+
}
17+
18+
if 2 * a == 1 {
19+
} else if 2 * a == 2 {
20+
} else if 2 * a == 1 {
21+
//~ ERROR ifs same condition
22+
} else if a == 1 {
23+
}
24+
25+
// See #659
26+
if cfg!(feature = "feature1-659") {
27+
1
28+
} else if cfg!(feature = "feature2-659") {
29+
2
30+
} else {
31+
3
32+
};
33+
34+
let mut v = vec![1];
35+
if v.pop() == None {
36+
// ok, functions
37+
} else if v.pop() == None {
38+
}
39+
40+
if v.len() == 42 {
41+
// ok, functions
42+
} else if v.len() == 42 {
43+
}
44+
}
45+
46+
fn main() {}

Diff for: tests/ui/ifs_same_cond.stderr

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
error: this `if` has the same condition as a previous if
2+
--> $DIR/ifs_same_cond.rs:9:15
3+
|
4+
LL | } else if b {
5+
| ^
6+
|
7+
= note: `-D clippy::ifs-same-cond` implied by `-D warnings`
8+
note: same as this
9+
--> $DIR/ifs_same_cond.rs:8:8
10+
|
11+
LL | if b {
12+
| ^
13+
14+
error: this `if` has the same condition as a previous if
15+
--> $DIR/ifs_same_cond.rs:14:15
16+
|
17+
LL | } else if a == 1 {
18+
| ^^^^^^
19+
|
20+
note: same as this
21+
--> $DIR/ifs_same_cond.rs:13:8
22+
|
23+
LL | if a == 1 {
24+
| ^^^^^^
25+
26+
error: this `if` has the same condition as a previous if
27+
--> $DIR/ifs_same_cond.rs:20:15
28+
|
29+
LL | } else if 2 * a == 1 {
30+
| ^^^^^^^^^^
31+
|
32+
note: same as this
33+
--> $DIR/ifs_same_cond.rs:18:8
34+
|
35+
LL | if 2 * a == 1 {
36+
| ^^^^^^^^^^
37+
38+
error: aborting due to 3 previous errors
39+

0 commit comments

Comments
 (0)