Skip to content

Commit 2d8b275

Browse files
committed
Split out tests
1 parent 76d0590 commit 2d8b275

14 files changed

+159
-89
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1128,6 +1128,7 @@ Released 2018-09-13
11281128
[`ok_expect`]: https://rust-lang.github.io/rust-clippy/master/index.html#ok_expect
11291129
[`op_ref`]: https://rust-lang.github.io/rust-clippy/master/index.html#op_ref
11301130
[`option_and_then_some`]: https://rust-lang.github.io/rust-clippy/master/index.html#option_and_then_some
1131+
[`option_expect_used`]: https://rust-lang.github.io/rust-clippy/master/index.html#option_expect_used
11311132
[`option_map_or_none`]: https://rust-lang.github.io/rust-clippy/master/index.html#option_map_or_none
11321133
[`option_map_unit_fn`]: https://rust-lang.github.io/rust-clippy/master/index.html#option_map_unit_fn
11331134
[`option_map_unwrap_or`]: https://rust-lang.github.io/rust-clippy/master/index.html#option_map_unwrap_or
@@ -1167,6 +1168,7 @@ Released 2018-09-13
11671168
[`ref_in_deref`]: https://rust-lang.github.io/rust-clippy/master/index.html#ref_in_deref
11681169
[`regex_macro`]: https://rust-lang.github.io/rust-clippy/master/index.html#regex_macro
11691170
[`replace_consts`]: https://rust-lang.github.io/rust-clippy/master/index.html#replace_consts
1171+
[`result_expect_used`]: https://rust-lang.github.io/rust-clippy/master/index.html#result_expect_used
11701172
[`result_map_unit_fn`]: https://rust-lang.github.io/rust-clippy/master/index.html#result_map_unit_fn
11711173
[`result_map_unwrap_or_else`]: https://rust-lang.github.io/rust-clippy/master/index.html#result_map_unwrap_or_else
11721174
[`result_unwrap_used`]: https://rust-lang.github.io/rust-clippy/master/index.html#result_unwrap_used

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
A collection of lints to catch common mistakes and improve your [Rust](https://github.com/rust-lang/rust) code.
88

9-
[There are 328 lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html)
9+
[There are 330 lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html)
1010

1111
We have a bunch of lint categories to allow you to choose how much Clippy is supposed to ~~annoy~~ help you:
1212

clippy_lints/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,9 @@ pub fn register_plugins(reg: &mut rustc_driver::plugin::Registry<'_>, conf: &Con
623623
mem_forget::MEM_FORGET,
624624
methods::CLONE_ON_REF_PTR,
625625
methods::GET_UNWRAP,
626+
methods::OPTION_EXPECT_USED,
626627
methods::OPTION_UNWRAP_USED,
628+
methods::RESULT_EXPECT_USED,
627629
methods::RESULT_UNWRAP_USED,
628630
methods::WRONG_PUB_SELF_CONVENTION,
629631
misc::FLOAT_CMP_CONST,

src/lintlist/mod.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ pub use lint::Lint;
66
pub use lint::LINT_LEVELS;
77

88
// begin lint list, do not remove this comment, it’s used in `update_lints`
9-
pub const ALL_LINTS: [Lint; 328] = [
9+
pub const ALL_LINTS: [Lint; 330] = [
1010
Lint {
1111
name: "absurd_extreme_comparisons",
1212
group: "correctness",
@@ -1386,6 +1386,13 @@ pub const ALL_LINTS: [Lint; 328] = [
13861386
deprecation: None,
13871387
module: "methods",
13881388
},
1389+
Lint {
1390+
name: "option_expect_used",
1391+
group: "restriction",
1392+
desc: "using `Option.expect()`, which might be better handled",
1393+
deprecation: None,
1394+
module: "methods",
1395+
},
13891396
Lint {
13901397
name: "option_map_or_none",
13911398
group: "style",
@@ -1652,6 +1659,13 @@ pub const ALL_LINTS: [Lint; 328] = [
16521659
deprecation: None,
16531660
module: "replace_consts",
16541661
},
1662+
Lint {
1663+
name: "result_expect_used",
1664+
group: "restriction",
1665+
desc: "using `Result.expect()`, which might be better handled",
1666+
deprecation: None,
1667+
module: "methods",
1668+
},
16551669
Lint {
16561670
name: "result_map_unit_fn",
16571671
group: "complexity",

tests/ui/expect_unwrap.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#![warn(
2+
clippy::option_unwrap_used,
3+
clippy::option_expect_used,
4+
clippy::result_unwrap_used,
5+
clippy::result_expect_used
6+
)]
7+
8+
fn expect_option() {
9+
let opt = Some(0);
10+
let _ = opt.expect("");
11+
}
12+
13+
fn expect_result() {
14+
let res: Result<u8, ()> = Ok(0);
15+
let _ = res.expect("");
16+
}
17+
fn unwrap_option() {
18+
let opt = Some(0);
19+
let _ = opt.unwrap();
20+
}
21+
22+
fn unwrap_result() {
23+
let res: Result<u8, ()> = Ok(0);
24+
let _ = res.unwrap();
25+
}
26+
27+
fn main() {
28+
expect_option();
29+
expect_result();
30+
unwrap_option();
31+
unwrap_result();
32+
}

tests/ui/expect_unwrap.stderr

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
error: used expect() on an Option value. If this value is an None it will panic
2+
--> $DIR/expect_unwrap.rs:10: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_unwrap.rs:15:13
11+
|
12+
LL | let _ = res.expect("");
13+
| ^^^^^^^^^^^^^^
14+
|
15+
= note: `-D clippy::result-expect-used` implied by `-D warnings`
16+
17+
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
18+
--> $DIR/expect_unwrap.rs:19:13
19+
|
20+
LL | let _ = opt.unwrap();
21+
| ^^^^^^^^^^^^
22+
|
23+
= note: `-D clippy::option-unwrap-used` implied by `-D warnings`
24+
25+
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
26+
--> $DIR/expect_unwrap.rs:24:13
27+
|
28+
LL | let _ = res.unwrap();
29+
| ^^^^^^^^^^^^
30+
|
31+
= note: `-D clippy::result-unwrap-used` implied by `-D warnings`
32+
33+
error: aborting due to 4 previous errors
34+

tests/ui/methods.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
// aux-build:option_helpers.rs
22
// compile-flags: --edition 2018
33

4-
#![warn(
5-
clippy::all,
6-
clippy::pedantic,
7-
clippy::option_unwrap_used,
8-
clippy::option_expect_used,
9-
clippy::result_expect_used
10-
)]
4+
#![warn(clippy::all, clippy::pedantic)]
115
#![allow(
126
clippy::blacklisted_name,
137
clippy::default_trait_access,
@@ -307,8 +301,8 @@ fn search_is_some() {
307301
let _ = foo.rposition().is_some();
308302
}
309303

310-
#[allow(clippy::similar_names)]
311304
fn main() {
312-
let opt = Some(0);
313-
let _ = opt.unwrap();
305+
option_methods();
306+
filter_next();
307+
search_is_some();
314308
}

tests/ui/methods.stderr

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -206,13 +206,5 @@ LL | | }
206206
LL | | ).is_some();
207207
| |______________________________^
208208

209-
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
210-
--> $DIR/methods.rs:307:13
211-
|
212-
LL | let _ = opt.unwrap();
213-
| ^^^^^^^^^^^^
214-
|
215-
= note: `-D clippy::option-unwrap-used` implied by `-D warnings`
216-
217-
error: aborting due to 24 previous errors
209+
error: aborting due to 23 previous errors
218210

tests/ui/panic.rs

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

tests/ui/panic.stderr

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

tests/ui/panic_unimplemented.rs

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -50,24 +50,6 @@ fn ok_escaped() {
5050
panic!("{case }}");
5151
}
5252

53-
fn unimplemented() {
54-
let a = 2;
55-
unimplemented!();
56-
let b = a + 2;
57-
}
58-
59-
fn unreachable() {
60-
let a = 2;
61-
unreachable!();
62-
let b = a + 2;
63-
}
64-
65-
fn todo() {
66-
let a = 2;
67-
todo!();
68-
let b = a + 2;
69-
}
70-
7153
fn main() {
7254
missing();
7355
ok_single();
@@ -76,7 +58,4 @@ fn main() {
7658
ok_inner();
7759
ok_nomsg();
7860
ok_escaped();
79-
unimplemented();
80-
unreachable();
81-
todo();
8261
}

tests/ui/panic_unimplemented.stderr

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -24,29 +24,5 @@ error: you probably are missing some parameter in your format string
2424
LL | panic!("{{{this}}}");
2525
| ^^^^^^^^^^^^
2626

27-
error: `unimplemented` should not be present in production code
28-
--> $DIR/panic_unimplemented.rs:55:5
29-
|
30-
LL | unimplemented!();
31-
| ^^^^^^^^^^^^^^^^^
32-
|
33-
= note: `-D clippy::unimplemented` implied by `-D warnings`
34-
35-
error: `unreachable` should not be present in production code
36-
--> $DIR/panic_unimplemented.rs:61:5
37-
|
38-
LL | unreachable!();
39-
| ^^^^^^^^^^^^^^^
40-
|
41-
= note: `-D clippy::unreachable` implied by `-D warnings`
42-
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
27+
error: aborting due to 4 previous errors
5228

tests/ui/panicking_macros.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#![warn(clippy::unimplemented, clippy::unreachable, clippy::todo, 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 todo() {
11+
let a = 2;
12+
todo!();
13+
let b = a + 2;
14+
}
15+
16+
fn unimplemented() {
17+
let a = 2;
18+
unimplemented!();
19+
let b = a + 2;
20+
}
21+
22+
fn unreachable() {
23+
let a = 2;
24+
unreachable!();
25+
let b = a + 2;
26+
}
27+
28+
fn main() {
29+
panic();
30+
todo();
31+
unimplemented();
32+
unreachable();
33+
}

tests/ui/panicking_macros.stderr

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
error: `panic` should not be present in production code
2+
--> $DIR/panicking_macros.rs:6:5
3+
|
4+
LL | panic!();
5+
| ^^^^^^^^^
6+
|
7+
= note: `-D clippy::panic` implied by `-D warnings`
8+
9+
error: `todo` should not be present in production code
10+
--> $DIR/panicking_macros.rs:12:5
11+
|
12+
LL | todo!();
13+
| ^^^^^^^^
14+
|
15+
= note: `-D clippy::todo` implied by `-D warnings`
16+
17+
error: `unimplemented` should not be present in production code
18+
--> $DIR/panicking_macros.rs:18:5
19+
|
20+
LL | unimplemented!();
21+
| ^^^^^^^^^^^^^^^^^
22+
|
23+
= note: `-D clippy::unimplemented` implied by `-D warnings`
24+
25+
error: `unreachable` should not be present in production code
26+
--> $DIR/panicking_macros.rs:24:5
27+
|
28+
LL | unreachable!();
29+
| ^^^^^^^^^^^^^^^
30+
|
31+
= note: `-D clippy::unreachable` implied by `-D warnings`
32+
33+
error: aborting due to 4 previous errors
34+

0 commit comments

Comments
 (0)