Skip to content

Commit 7f454d8

Browse files
committed
Split out tests
1 parent a7ad78f commit 7f454d8

18 files changed

+245
-171
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -1129,6 +1129,7 @@ Released 2018-09-13
11291129
[`ok_expect`]: https://rust-lang.github.io/rust-clippy/master/index.html#ok_expect
11301130
[`op_ref`]: https://rust-lang.github.io/rust-clippy/master/index.html#op_ref
11311131
[`option_and_then_some`]: https://rust-lang.github.io/rust-clippy/master/index.html#option_and_then_some
1132+
[`option_expect_used`]: https://rust-lang.github.io/rust-clippy/master/index.html#option_expect_used
11321133
[`option_map_or_none`]: https://rust-lang.github.io/rust-clippy/master/index.html#option_map_or_none
11331134
[`option_map_unit_fn`]: https://rust-lang.github.io/rust-clippy/master/index.html#option_map_unit_fn
11341135
[`option_map_unwrap_or`]: https://rust-lang.github.io/rust-clippy/master/index.html#option_map_unwrap_or
@@ -1168,6 +1169,7 @@ Released 2018-09-13
11681169
[`ref_in_deref`]: https://rust-lang.github.io/rust-clippy/master/index.html#ref_in_deref
11691170
[`regex_macro`]: https://rust-lang.github.io/rust-clippy/master/index.html#regex_macro
11701171
[`replace_consts`]: https://rust-lang.github.io/rust-clippy/master/index.html#replace_consts
1172+
[`result_expect_used`]: https://rust-lang.github.io/rust-clippy/master/index.html#result_expect_used
11711173
[`result_map_unit_fn`]: https://rust-lang.github.io/rust-clippy/master/index.html#result_map_unit_fn
11721174
[`result_map_unwrap_or_else`]: https://rust-lang.github.io/rust-clippy/master/index.html#result_map_unwrap_or_else
11731175
[`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 329 lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html)
9+
[There are 331 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
@@ -625,7 +625,9 @@ pub fn register_plugins(reg: &mut rustc_driver::plugin::Registry<'_>, conf: &Con
625625
mem_forget::MEM_FORGET,
626626
methods::CLONE_ON_REF_PTR,
627627
methods::GET_UNWRAP,
628+
methods::OPTION_EXPECT_USED,
628629
methods::OPTION_UNWRAP_USED,
630+
methods::RESULT_EXPECT_USED,
629631
methods::RESULT_UNWRAP_USED,
630632
methods::WRONG_PUB_SELF_CONVENTION,
631633
misc::FLOAT_CMP_CONST,

clippy_lints/src/methods/mod.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,10 @@ declare_clippy_lint! {
111111
///
112112
/// Better:
113113
///
114-
/// ```rust
114+
/// ```ignore
115115
/// let opt = Some(1);
116116
/// opt?;
117+
/// # Some::<()>(())
117118
/// ```
118119
pub OPTION_EXPECT_USED,
119120
restriction,
@@ -139,9 +140,10 @@ declare_clippy_lint! {
139140
///
140141
/// Better:
141142
///
142-
/// ```rust
143+
/// ```
143144
/// let res: Result<usize, ()> = Ok(1);
144145
/// res?;
146+
/// # Ok::<(), ()>(())
145147
/// ```
146148
pub RESULT_EXPECT_USED,
147149
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; 329] = [
9+
pub const ALL_LINTS: [Lint; 331] = [
1010
Lint {
1111
name: "absurd_extreme_comparisons",
1212
group: "correctness",
@@ -1393,6 +1393,13 @@ pub const ALL_LINTS: [Lint; 329] = [
13931393
deprecation: None,
13941394
module: "methods",
13951395
},
1396+
Lint {
1397+
name: "option_expect_used",
1398+
group: "restriction",
1399+
desc: "using `Option.expect()`, which might be better handled",
1400+
deprecation: None,
1401+
module: "methods",
1402+
},
13961403
Lint {
13971404
name: "option_map_or_none",
13981405
group: "style",
@@ -1459,7 +1466,7 @@ pub const ALL_LINTS: [Lint; 329] = [
14591466
Lint {
14601467
name: "panic",
14611468
group: "restriction",
1462-
desc: "missing parameters in `panic!` calls",
1469+
desc: "usage of the `panic!` macro",
14631470
deprecation: None,
14641471
module: "panic_unimplemented",
14651472
},
@@ -1659,6 +1666,13 @@ pub const ALL_LINTS: [Lint; 329] = [
16591666
deprecation: None,
16601667
module: "replace_consts",
16611668
},
1669+
Lint {
1670+
name: "result_expect_used",
1671+
group: "restriction",
1672+
desc: "using `Result.expect()`, which might be better handled",
1673+
deprecation: None,
1674+
module: "methods",
1675+
},
16621676
Lint {
16631677
name: "result_map_unit_fn",
16641678
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)