Skip to content

Commit e910a83

Browse files
committed
Add regression test for clippy issue 7723
1 parent 8ec8372 commit e910a83

File tree

3 files changed

+158
-0
lines changed

3 files changed

+158
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// run-rustfix
2+
#![crate_type = "lib"]
3+
#![no_std]
4+
#![warn(clippy::if_then_panic)]
5+
6+
pub fn main() {
7+
let a = &[1, 2, 3];
8+
let c = Some(2);
9+
if !a.is_empty()
10+
&& a.len() == 3
11+
&& c != None
12+
&& !a.is_empty()
13+
&& a.len() == 3
14+
&& !a.is_empty()
15+
&& a.len() == 3
16+
&& !a.is_empty()
17+
&& a.len() == 3
18+
{
19+
panic!("qaqaq{:?}", a);
20+
}
21+
assert!(a.is_empty(), "qaqaq{:?}", a);
22+
assert!(a.is_empty(), "qwqwq");
23+
if a.len() == 3 {
24+
format_args!("qwq");
25+
format_args!("qwq");
26+
format_args!("qwq");
27+
}
28+
if let Some(b) = c {
29+
panic!("orz {}", b);
30+
}
31+
if a.len() == 3 {
32+
panic!("qaqaq");
33+
} else {
34+
format_args!("qwq");
35+
}
36+
let b = &[1, 2, 3];
37+
assert!(!b.is_empty(), "panic1");
38+
assert!(!(b.is_empty() && a.is_empty()), "panic2");
39+
assert!(!(a.is_empty() && !b.is_empty()), "panic3");
40+
assert!(!(b.is_empty() || a.is_empty()), "panic4");
41+
assert!(!(a.is_empty() || !b.is_empty()), "panic5");
42+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// run-rustfix
2+
#![crate_type = "lib"]
3+
#![no_std]
4+
#![warn(clippy::if_then_panic)]
5+
6+
pub fn main() {
7+
let a = &[1, 2, 3];
8+
let c = Some(2);
9+
if !a.is_empty()
10+
&& a.len() == 3
11+
&& c != None
12+
&& !a.is_empty()
13+
&& a.len() == 3
14+
&& !a.is_empty()
15+
&& a.len() == 3
16+
&& !a.is_empty()
17+
&& a.len() == 3
18+
{
19+
panic!("qaqaq{:?}", a);
20+
}
21+
if !a.is_empty() {
22+
panic!("qaqaq{:?}", a);
23+
}
24+
if !a.is_empty() {
25+
panic!("qwqwq");
26+
}
27+
if a.len() == 3 {
28+
format_args!("qwq");
29+
format_args!("qwq");
30+
format_args!("qwq");
31+
}
32+
if let Some(b) = c {
33+
panic!("orz {}", b);
34+
}
35+
if a.len() == 3 {
36+
panic!("qaqaq");
37+
} else {
38+
format_args!("qwq");
39+
}
40+
let b = &[1, 2, 3];
41+
if b.is_empty() {
42+
panic!("panic1");
43+
}
44+
if b.is_empty() && a.is_empty() {
45+
panic!("panic2");
46+
}
47+
if a.is_empty() && !b.is_empty() {
48+
panic!("panic3");
49+
}
50+
if b.is_empty() || a.is_empty() {
51+
panic!("panic4");
52+
}
53+
if a.is_empty() || !b.is_empty() {
54+
panic!("panic5");
55+
}
56+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
error: only a `panic!` in `if`-then statement
2+
--> $DIR/if_then_panic_core.rs:21:5
3+
|
4+
LL | / if !a.is_empty() {
5+
LL | | panic!("qaqaq{:?}", a);
6+
LL | | }
7+
| |_____^ help: try: `assert!(a.is_empty(), "qaqaq{:?}", a);`
8+
|
9+
= note: `-D clippy::if-then-panic` implied by `-D warnings`
10+
11+
error: only a `panic!` in `if`-then statement
12+
--> $DIR/if_then_panic_core.rs:24:5
13+
|
14+
LL | / if !a.is_empty() {
15+
LL | | panic!("qwqwq");
16+
LL | | }
17+
| |_____^ help: try: `assert!(a.is_empty(), "qwqwq");`
18+
19+
error: only a `panic!` in `if`-then statement
20+
--> $DIR/if_then_panic_core.rs:41:5
21+
|
22+
LL | / if b.is_empty() {
23+
LL | | panic!("panic1");
24+
LL | | }
25+
| |_____^ help: try: `assert!(!b.is_empty(), "panic1");`
26+
27+
error: only a `panic!` in `if`-then statement
28+
--> $DIR/if_then_panic_core.rs:44:5
29+
|
30+
LL | / if b.is_empty() && a.is_empty() {
31+
LL | | panic!("panic2");
32+
LL | | }
33+
| |_____^ help: try: `assert!(!(b.is_empty() && a.is_empty()), "panic2");`
34+
35+
error: only a `panic!` in `if`-then statement
36+
--> $DIR/if_then_panic_core.rs:47:5
37+
|
38+
LL | / if a.is_empty() && !b.is_empty() {
39+
LL | | panic!("panic3");
40+
LL | | }
41+
| |_____^ help: try: `assert!(!(a.is_empty() && !b.is_empty()), "panic3");`
42+
43+
error: only a `panic!` in `if`-then statement
44+
--> $DIR/if_then_panic_core.rs:50:5
45+
|
46+
LL | / if b.is_empty() || a.is_empty() {
47+
LL | | panic!("panic4");
48+
LL | | }
49+
| |_____^ help: try: `assert!(!(b.is_empty() || a.is_empty()), "panic4");`
50+
51+
error: only a `panic!` in `if`-then statement
52+
--> $DIR/if_then_panic_core.rs:53:5
53+
|
54+
LL | / if a.is_empty() || !b.is_empty() {
55+
LL | | panic!("panic5");
56+
LL | | }
57+
| |_____^ help: try: `assert!(!(a.is_empty() || !b.is_empty()), "panic5");`
58+
59+
error: aborting due to 7 previous errors
60+

0 commit comments

Comments
 (0)