Skip to content

Commit 9db10c0

Browse files
committed
Add tests for panic and todo, fix test order for panic
1 parent 1c74067 commit 9db10c0

File tree

5 files changed

+33
-3
lines changed

5 files changed

+33
-3
lines changed

clippy_lints/src/panic_unimplemented.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for PanicUnimplemented {
115115
let span = get_outer_span(expr);
116116
span_lint(cx, PANIC, span,
117117
"`panic` should not be present in production code");
118-
//} else {
119118
match_panic(params, expr, cx);
120119
}
121120
}

tests/ui/panic.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#![warn(clippy::panic)]
2+
#![allow(clippy::assertions_on_constants)]
3+
4+
fn panic() {
5+
let a = 2;
6+
panic!();
7+
let b = a + 2;
8+
}
9+
10+
fn main() {
11+
panic();
12+
}

tests/ui/panic.stderr

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
error: `panic` should not be present in production code
2+
--> $DIR/panic.rs:6:5
3+
|
4+
LL | panic!();
5+
| ^^^^^^^^^
6+
|
7+
= note: `-D clippy::panic` implied by `-D warnings`
8+
9+
error: aborting due to previous error
10+

tests/ui/panic_unimplemented.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![warn(clippy::panic_params, clippy::unimplemented, clippy::unreachable)]
1+
#![warn(clippy::panic_params, clippy::unimplemented, clippy::unreachable, clippy::todo)]
22
#![allow(clippy::assertions_on_constants)]
33
fn missing() {
44
if true {
@@ -78,4 +78,5 @@ fn main() {
7878
ok_escaped();
7979
unimplemented();
8080
unreachable();
81+
todo();
8182
}

tests/ui/panic_unimplemented.stderr

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,13 @@ LL | unreachable!();
4040
|
4141
= note: `-D clippy::unreachable` implied by `-D warnings`
4242

43-
error: aborting due to 6 previous errors
43+
error: `todo` should not be present in production code
44+
--> $DIR/panic_unimplemented.rs:67:5
45+
|
46+
LL | todo!();
47+
| ^^^^^^^^
48+
|
49+
= note: `-D clippy::todo` implied by `-D warnings`
50+
51+
error: aborting due to 7 previous errors
4452

0 commit comments

Comments
 (0)