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

+2
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

+1-1
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

+2
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

+4-2
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

+1-1
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

+16-2
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

+16
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

+18
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

+4-10
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

+1-9
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

+55-6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,61 @@
1-
#![warn(clippy::panic)]
1+
#![warn(clippy::panic_params)]
22
#![allow(clippy::assertions_on_constants)]
3+
fn missing() {
4+
if true {
5+
panic!("{}");
6+
} else if false {
7+
panic!("{:?}");
8+
} else {
9+
assert!(true, "here be missing values: {}");
10+
}
311

4-
fn panic() {
5-
let a = 2;
6-
panic!();
7-
let b = a + 2;
12+
panic!("{{{this}}}");
13+
}
14+
15+
fn ok_single() {
16+
panic!("foo bar");
17+
}
18+
19+
fn ok_inner() {
20+
// Test for #768
21+
assert!("foo bar".contains(&format!("foo {}", "bar")));
22+
}
23+
24+
fn ok_multiple() {
25+
panic!("{}", "This is {ok}");
26+
}
27+
28+
fn ok_bracket() {
29+
match 42 {
30+
1337 => panic!("{so is this"),
31+
666 => panic!("so is this}"),
32+
_ => panic!("}so is that{"),
33+
}
34+
}
35+
36+
const ONE: u32 = 1;
37+
38+
fn ok_nomsg() {
39+
assert!({ 1 == ONE });
40+
assert!(if 1 == ONE { ONE == 1 } else { false });
41+
}
42+
43+
fn ok_escaped() {
44+
panic!("{{ why should this not be ok? }}");
45+
panic!(" or {{ that ?");
46+
panic!(" or }} this ?");
47+
panic!(" {or {{ that ?");
48+
panic!(" }or }} this ?");
49+
panic!("{{ test }");
50+
panic!("{case }}");
851
}
952

1053
fn main() {
11-
panic();
54+
missing();
55+
ok_single();
56+
ok_multiple();
57+
ok_bracket();
58+
ok_inner();
59+
ok_nomsg();
60+
ok_escaped();
1261
}

tests/ui/panic.stderr

+24-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,28 @@
1-
error: `panic` should not be present in production code
2-
--> $DIR/panic.rs:6:5
1+
error: you probably are missing some parameter in your format string
2+
--> $DIR/panic.rs:5:16
33
|
4-
LL | panic!();
5-
| ^^^^^^^^^
4+
LL | panic!("{}");
5+
| ^^^^
66
|
7-
= note: `-D clippy::panic` implied by `-D warnings`
7+
= note: `-D clippy::panic-params` implied by `-D warnings`
88

9-
error: aborting due to previous error
9+
error: you probably are missing some parameter in your format string
10+
--> $DIR/panic.rs:7:16
11+
|
12+
LL | panic!("{:?}");
13+
| ^^^^^^
14+
15+
error: you probably are missing some parameter in your format string
16+
--> $DIR/panic.rs:9:23
17+
|
18+
LL | assert!(true, "here be missing values: {}");
19+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
20+
21+
error: you probably are missing some parameter in your format string
22+
--> $DIR/panic.rs:12:12
23+
|
24+
LL | panic!("{{{this}}}");
25+
| ^^^^^^^^^^^^
26+
27+
error: aborting due to 4 previous errors
1028

tests/ui/panic_unimplemented.rs

-82
This file was deleted.

0 commit comments

Comments
 (0)