Skip to content

Commit e323c2d

Browse files
committed
Split out tests further
Add missing tests
1 parent 2d8b275 commit e323c2d

File tree

9 files changed

+74
-72
lines changed

9 files changed

+74
-72
lines changed

clippy_lints/src/panic_unimplemented.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ declare_clippy_lint! {
3838
/// ```
3939
pub PANIC,
4040
restriction,
41-
"missing parameters in `panic!` calls"
41+
"usage of the `panic!` macro"
4242
}
4343

4444
declare_clippy_lint! {

tests/ui/expect.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#![warn(clippy::option_expect_used, clippy::result_expect_used)]
2+
3+
fn expect_option() {
4+
let opt = Some(0);
5+
let _ = opt.expect("");
6+
}
7+
8+
fn expect_result() {
9+
let res: Result<u8, ()> = Ok(0);
10+
let _ = res.expect("");
11+
}
12+
13+
fn main() {
14+
expect_option();
15+
expect_result();
16+
}

tests/ui/expect.stderr

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
error: used expect() on an Option value. If this value is an None it will panic
2+
--> $DIR/expect.rs:5:13
3+
|
4+
LL | let _ = opt.expect("");
5+
| ^^^^^^^^^^^^^^
6+
|
7+
= note: `-D clippy::option-expect-used` implied by `-D warnings`
8+
9+
error: used expect() on a Result value. If this value is an Err it will panic
10+
--> $DIR/expect.rs:10:13
11+
|
12+
LL | let _ = res.expect("");
13+
| ^^^^^^^^^^^^^^
14+
|
15+
= note: `-D clippy::result-expect-used` implied by `-D warnings`
16+
17+
error: aborting due to 2 previous errors
18+

tests/ui/expect_unwrap.rs

Lines changed: 0 additions & 32 deletions
This file was deleted.

tests/ui/expect_unwrap.stderr

Lines changed: 0 additions & 34 deletions
This file was deleted.

tests/ui/panic_unimplemented.rs renamed to tests/ui/panic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![warn(clippy::panic_params, clippy::unimplemented, clippy::unreachable, clippy::todo)]
1+
#![warn(clippy::panic_params)]
22
#![allow(clippy::assertions_on_constants)]
33
fn missing() {
44
if true {

tests/ui/panic_unimplemented.stderr renamed to tests/ui/panic.stderr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
error: you probably are missing some parameter in your format string
2-
--> $DIR/panic_unimplemented.rs:5:16
2+
--> $DIR/panic.rs:5:16
33
|
44
LL | panic!("{}");
55
| ^^^^
66
|
77
= note: `-D clippy::panic-params` implied by `-D warnings`
88

99
error: you probably are missing some parameter in your format string
10-
--> $DIR/panic_unimplemented.rs:7:16
10+
--> $DIR/panic.rs:7:16
1111
|
1212
LL | panic!("{:?}");
1313
| ^^^^^^
1414

1515
error: you probably are missing some parameter in your format string
16-
--> $DIR/panic_unimplemented.rs:9:23
16+
--> $DIR/panic.rs:9:23
1717
|
1818
LL | assert!(true, "here be missing values: {}");
1919
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2020

2121
error: you probably are missing some parameter in your format string
22-
--> $DIR/panic_unimplemented.rs:12:12
22+
--> $DIR/panic.rs:12:12
2323
|
2424
LL | panic!("{{{this}}}");
2525
| ^^^^^^^^^^^^

tests/ui/unwrap.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#![warn(clippy::option_unwrap_used, clippy::result_unwrap_used)]
2+
3+
fn unwrap_option() {
4+
let opt = Some(0);
5+
let _ = opt.unwrap();
6+
}
7+
8+
fn unwrap_result() {
9+
let res: Result<u8, ()> = Ok(0);
10+
let _ = res.unwrap();
11+
}
12+
13+
fn main() {
14+
unwrap_option();
15+
unwrap_result();
16+
}

tests/ui/unwrap.stderr

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
error: used unwrap() on an Option value. If you don't want to handle the None case gracefully, consider using expect() to provide a better panic message
2+
--> $DIR/unwrap.rs:5:13
3+
|
4+
LL | let _ = opt.unwrap();
5+
| ^^^^^^^^^^^^
6+
|
7+
= note: `-D clippy::option-unwrap-used` implied by `-D warnings`
8+
9+
error: used unwrap() on a Result value. If you don't want to handle the Err case gracefully, consider using expect() to provide a better panic message
10+
--> $DIR/unwrap.rs:10:13
11+
|
12+
LL | let _ = res.unwrap();
13+
| ^^^^^^^^^^^^
14+
|
15+
= note: `-D clippy::result-unwrap-used` implied by `-D warnings`
16+
17+
error: aborting due to 2 previous errors
18+

0 commit comments

Comments
 (0)