Skip to content

Commit 6a48a71

Browse files
committed
Split out tests
1 parent 57dcc0d commit 6a48a71

18 files changed

+245
-171
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,

clippy_lints/src/methods/mod.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,10 @@ declare_clippy_lint! {
110110
///
111111
/// Better:
112112
///
113-
/// ```rust
113+
/// ```ignore
114114
/// let opt = Some(1);
115115
/// opt?;
116+
/// # Some::<()>(())
116117
/// ```
117118
pub OPTION_EXPECT_USED,
118119
restriction,
@@ -138,9 +139,10 @@ declare_clippy_lint! {
138139
///
139140
/// Better:
140141
///
141-
/// ```rust
142+
/// ```
142143
/// let res: Result<usize, ()> = Ok(1);
143144
/// res?;
145+
/// # Ok::<(), ()>(())
144146
/// ```
145147
pub RESULT_EXPECT_USED,
146148
restriction,

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! {

src/lintlist/mod.rs

Lines changed: 16 additions & 2 deletions
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",
@@ -1452,7 +1459,7 @@ pub const ALL_LINTS: [Lint; 328] = [
14521459
Lint {
14531460
name: "panic",
14541461
group: "restriction",
1455-
desc: "missing parameters in `panic!` calls",
1462+
desc: "usage of the `panic!` macro",
14561463
deprecation: None,
14571464
module: "panic_unimplemented",
14581465
},
@@ -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.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/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

0 commit comments

Comments
 (0)