Skip to content

Commit 00821ca

Browse files
committed
Auto merge of rust-lang#7810 - camsteffen:if-then-panic-pedantic, r=flip1995
Move if_then_panic to pedantic and rename to manual_assert Closes rust-lang#7718 changelog: none (lint added since last release)
2 parents 7788af9 + 022146d commit 00821ca

14 files changed

+43
-50
lines changed

CHANGELOG.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Current beta, release 2021-12-02
3434
[#7610](https://github.com/rust-lang/rust-clippy/pull/7610)
3535
* [`same_name_method`]
3636
[#7653](https://github.com/rust-lang/rust-clippy/pull/7653)
37-
* [`if_then_panic`] [#7669](https://github.com/rust-lang/rust-clippy/pull/7669)
37+
* [`manual_assert`] [#7669](https://github.com/rust-lang/rust-clippy/pull/7669)
3838
* [`non_send_fields_in_send_ty`]
3939
[#7709](https://github.com/rust-lang/rust-clippy/pull/7709)
4040
* [`equatable_if_let`]
@@ -139,7 +139,7 @@ Current beta, release 2021-12-02
139139
`rsplitn` is used [#7663](https://github.com/rust-lang/rust-clippy/pull/7663)
140140
* [`while_let_on_iterator`]: Produce correct suggestion when using `&mut`
141141
[#7690](https://github.com/rust-lang/rust-clippy/pull/7690)
142-
* [`if_then_panic`]: No better handles complex conditions
142+
* [`manual_assert`]: No better handles complex conditions
143143
[#7741](https://github.com/rust-lang/rust-clippy/pull/7741)
144144
* Correctly handle signs in exponents in numeric literals lints
145145
[#7747](https://github.com/rust-lang/rust-clippy/pull/7747)
@@ -2895,7 +2895,6 @@ Released 2018-09-13
28952895
[`if_let_redundant_pattern_matching`]: https://rust-lang.github.io/rust-clippy/master/index.html#if_let_redundant_pattern_matching
28962896
[`if_not_else`]: https://rust-lang.github.io/rust-clippy/master/index.html#if_not_else
28972897
[`if_same_then_else`]: https://rust-lang.github.io/rust-clippy/master/index.html#if_same_then_else
2898-
[`if_then_panic`]: https://rust-lang.github.io/rust-clippy/master/index.html#if_then_panic
28992898
[`if_then_some_else_none`]: https://rust-lang.github.io/rust-clippy/master/index.html#if_then_some_else_none
29002899
[`ifs_same_cond`]: https://rust-lang.github.io/rust-clippy/master/index.html#ifs_same_cond
29012900
[`implicit_clone`]: https://rust-lang.github.io/rust-clippy/master/index.html#implicit_clone
@@ -2953,6 +2952,7 @@ Released 2018-09-13
29532952
[`lossy_float_literal`]: https://rust-lang.github.io/rust-clippy/master/index.html#lossy_float_literal
29542953
[`macro_use_imports`]: https://rust-lang.github.io/rust-clippy/master/index.html#macro_use_imports
29552954
[`main_recursion`]: https://rust-lang.github.io/rust-clippy/master/index.html#main_recursion
2955+
[`manual_assert`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_assert
29562956
[`manual_async_fn`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_async_fn
29572957
[`manual_filter_map`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_filter_map
29582958
[`manual_find_map`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_find_map

clippy_lints/src/lib.register_all.rs

-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ store.register_group(true, "clippy::all", Some("clippy_all"), vec![
7676
LintId::of(get_last_with_len::GET_LAST_WITH_LEN),
7777
LintId::of(identity_op::IDENTITY_OP),
7878
LintId::of(if_let_mutex::IF_LET_MUTEX),
79-
LintId::of(if_then_panic::IF_THEN_PANIC),
8079
LintId::of(indexing_slicing::OUT_OF_BOUNDS_INDEXING),
8180
LintId::of(infinite_iter::INFINITE_ITER),
8281
LintId::of(inherent_to_string::INHERENT_TO_STRING),

clippy_lints/src/lib.register_lints.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,6 @@ store.register_lints(&[
159159
identity_op::IDENTITY_OP,
160160
if_let_mutex::IF_LET_MUTEX,
161161
if_not_else::IF_NOT_ELSE,
162-
if_then_panic::IF_THEN_PANIC,
163162
if_then_some_else_none::IF_THEN_SOME_ELSE_NONE,
164163
implicit_hasher::IMPLICIT_HASHER,
165164
implicit_return::IMPLICIT_RETURN,
@@ -216,6 +215,7 @@ store.register_lints(&[
216215
loops::WHILE_LET_ON_ITERATOR,
217216
macro_use::MACRO_USE_IMPORTS,
218217
main_recursion::MAIN_RECURSION,
218+
manual_assert::MANUAL_ASSERT,
219219
manual_async_fn::MANUAL_ASYNC_FN,
220220
manual_map::MANUAL_MAP,
221221
manual_non_exhaustive::MANUAL_NON_EXHAUSTIVE,

clippy_lints/src/lib.register_pedantic.rs

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ store.register_group(true, "clippy::pedantic", Some("clippy_pedantic"), vec![
4848
LintId::of(loops::EXPLICIT_INTO_ITER_LOOP),
4949
LintId::of(loops::EXPLICIT_ITER_LOOP),
5050
LintId::of(macro_use::MACRO_USE_IMPORTS),
51+
LintId::of(manual_assert::MANUAL_ASSERT),
5152
LintId::of(manual_ok_or::MANUAL_OK_OR),
5253
LintId::of(match_on_vec_items::MATCH_ON_VEC_ITEMS),
5354
LintId::of(matches::MATCH_BOOL),

clippy_lints/src/lib.register_style.rs

-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ store.register_group(true, "clippy::style", Some("clippy_style"), vec![
2727
LintId::of(functions::DOUBLE_MUST_USE),
2828
LintId::of(functions::MUST_USE_UNIT),
2929
LintId::of(functions::RESULT_UNIT_ERR),
30-
LintId::of(if_then_panic::IF_THEN_PANIC),
3130
LintId::of(inherent_to_string::INHERENT_TO_STRING),
3231
LintId::of(len_zero::COMPARISON_TO_EMPTY),
3332
LintId::of(len_zero::LEN_WITHOUT_IS_EMPTY),

clippy_lints/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,6 @@ mod get_last_with_len;
228228
mod identity_op;
229229
mod if_let_mutex;
230230
mod if_not_else;
231-
mod if_then_panic;
232231
mod if_then_some_else_none;
233232
mod implicit_hasher;
234233
mod implicit_return;
@@ -255,6 +254,7 @@ mod literal_representation;
255254
mod loops;
256255
mod macro_use;
257256
mod main_recursion;
257+
mod manual_assert;
258258
mod manual_async_fn;
259259
mod manual_map;
260260
mod manual_non_exhaustive;
@@ -772,7 +772,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
772772
store.register_late_pass(move || Box::new(self_named_constructors::SelfNamedConstructors));
773773
store.register_late_pass(move || Box::new(feature_name::FeatureName));
774774
store.register_late_pass(move || Box::new(iter_not_returning_iterator::IterNotReturningIterator));
775-
store.register_late_pass(move || Box::new(if_then_panic::IfThenPanic));
775+
store.register_late_pass(move || Box::new(manual_assert::ManualAssert));
776776
let enable_raw_pointer_heuristic_for_send = conf.enable_raw_pointer_heuristic_for_send;
777777
store.register_late_pass(move || Box::new(non_send_fields_in_send_ty::NonSendFieldInSendTy::new(enable_raw_pointer_heuristic_for_send)));
778778
store.register_late_pass(move || Box::new(undocumented_unsafe_blocks::UndocumentedUnsafeBlocks::default()));

clippy_lints/src/if_then_panic.rs renamed to clippy_lints/src/manual_assert.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ declare_clippy_lint! {
2626
/// let sad_people: Vec<&str> = vec![];
2727
/// assert!(sad_people.is_empty(), "there are sad people: {:?}", sad_people);
2828
/// ```
29-
pub IF_THEN_PANIC,
30-
style,
29+
pub MANUAL_ASSERT,
30+
pedantic,
3131
"`panic!` and only a `panic!` in `if`-then statement"
3232
}
3333

34-
declare_lint_pass!(IfThenPanic => [IF_THEN_PANIC]);
34+
declare_lint_pass!(ManualAssert => [MANUAL_ASSERT]);
3535

36-
impl LateLintPass<'_> for IfThenPanic {
36+
impl LateLintPass<'_> for ManualAssert {
3737
fn check_expr(&mut self, cx: &LateContext<'_>, expr: &Expr<'_>) {
3838
if_chain! {
3939
if let Expr {
@@ -86,7 +86,7 @@ impl LateLintPass<'_> for IfThenPanic {
8686

8787
span_lint_and_sugg(
8888
cx,
89-
IF_THEN_PANIC,
89+
MANUAL_ASSERT,
9090
expr.span,
9191
"only a `panic!` in `if`-then statement",
9292
"try",

tests/ui/fallible_impl_from.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#![deny(clippy::fallible_impl_from)]
2-
#![allow(clippy::if_then_panic)]
32

43
// docs example
54
struct Foo(i32);

tests/ui/fallible_impl_from.stderr

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: consider implementing `TryFrom` instead
2-
--> $DIR/fallible_impl_from.rs:6:1
2+
--> $DIR/fallible_impl_from.rs:5:1
33
|
44
LL | / impl From<String> for Foo {
55
LL | | fn from(s: String) -> Self {
@@ -15,13 +15,13 @@ LL | #![deny(clippy::fallible_impl_from)]
1515
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
1616
= help: `From` is intended for infallible conversions only. Use `TryFrom` if there's a possibility for the conversion to fail
1717
note: potential failure(s)
18-
--> $DIR/fallible_impl_from.rs:8:13
18+
--> $DIR/fallible_impl_from.rs:7:13
1919
|
2020
LL | Foo(s.parse().unwrap())
2121
| ^^^^^^^^^^^^^^^^^^
2222

2323
error: consider implementing `TryFrom` instead
24-
--> $DIR/fallible_impl_from.rs:27:1
24+
--> $DIR/fallible_impl_from.rs:26:1
2525
|
2626
LL | / impl From<usize> for Invalid {
2727
LL | | fn from(i: usize) -> Invalid {
@@ -34,14 +34,14 @@ LL | | }
3434
|
3535
= help: `From` is intended for infallible conversions only. Use `TryFrom` if there's a possibility for the conversion to fail
3636
note: potential failure(s)
37-
--> $DIR/fallible_impl_from.rs:30:13
37+
--> $DIR/fallible_impl_from.rs:29:13
3838
|
3939
LL | panic!();
4040
| ^^^^^^^^
4141
= note: this error originates in the macro `$crate::panic::panic_2015` (in Nightly builds, run with -Z macro-backtrace for more info)
4242

4343
error: consider implementing `TryFrom` instead
44-
--> $DIR/fallible_impl_from.rs:36:1
44+
--> $DIR/fallible_impl_from.rs:35:1
4545
|
4646
LL | / impl From<Option<String>> for Invalid {
4747
LL | | fn from(s: Option<String>) -> Invalid {
@@ -54,7 +54,7 @@ LL | | }
5454
|
5555
= help: `From` is intended for infallible conversions only. Use `TryFrom` if there's a possibility for the conversion to fail
5656
note: potential failure(s)
57-
--> $DIR/fallible_impl_from.rs:38:17
57+
--> $DIR/fallible_impl_from.rs:37:17
5858
|
5959
LL | let s = s.unwrap();
6060
| ^^^^^^^^^^
@@ -68,7 +68,7 @@ LL | panic!("{:?}", s);
6868
= note: this error originates in the macro `$crate::panic::panic_2015` (in Nightly builds, run with -Z macro-backtrace for more info)
6969

7070
error: consider implementing `TryFrom` instead
71-
--> $DIR/fallible_impl_from.rs:54:1
71+
--> $DIR/fallible_impl_from.rs:53:1
7272
|
7373
LL | / impl<'a> From<&'a mut <Box<u32> as ProjStrTrait>::ProjString> for Invalid {
7474
LL | | fn from(s: &'a mut <Box<u32> as ProjStrTrait>::ProjString) -> Invalid {
@@ -81,7 +81,7 @@ LL | | }
8181
|
8282
= help: `From` is intended for infallible conversions only. Use `TryFrom` if there's a possibility for the conversion to fail
8383
note: potential failure(s)
84-
--> $DIR/fallible_impl_from.rs:56:12
84+
--> $DIR/fallible_impl_from.rs:55:12
8585
|
8686
LL | if s.parse::<u32>().ok().unwrap() != 42 {
8787
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

tests/ui/if_then_panic.fixed renamed to tests/ui/manual_assert.fixed

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// run-rustfix
2-
#![warn(clippy::if_then_panic)]
2+
#![warn(clippy::manual_assert)]
33

44
fn main() {
55
let a = vec![1, 2, 3];

tests/ui/if_then_panic.rs renamed to tests/ui/manual_assert.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// run-rustfix
2-
#![warn(clippy::if_then_panic)]
2+
#![warn(clippy::manual_assert)]
33

44
fn main() {
55
let a = vec![1, 2, 3];

tests/ui/if_then_panic.stderr renamed to tests/ui/manual_assert.stderr

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,55 @@
11
error: only a `panic!` in `if`-then statement
2-
--> $DIR/if_then_panic.rs:19:5
2+
--> $DIR/manual_assert.rs:19:5
33
|
44
LL | / if !a.is_empty() {
55
LL | | panic!("qaqaq{:?}", a);
66
LL | | }
77
| |_____^ help: try: `assert!(a.is_empty(), "qaqaq{:?}", a);`
88
|
9-
= note: `-D clippy::if-then-panic` implied by `-D warnings`
9+
= note: `-D clippy::manual-assert` implied by `-D warnings`
1010

1111
error: only a `panic!` in `if`-then statement
12-
--> $DIR/if_then_panic.rs:22:5
12+
--> $DIR/manual_assert.rs:22:5
1313
|
1414
LL | / if !a.is_empty() {
1515
LL | | panic!("qwqwq");
1616
LL | | }
1717
| |_____^ help: try: `assert!(a.is_empty(), "qwqwq");`
1818

1919
error: only a `panic!` in `if`-then statement
20-
--> $DIR/if_then_panic.rs:39:5
20+
--> $DIR/manual_assert.rs:39:5
2121
|
2222
LL | / if b.is_empty() {
2323
LL | | panic!("panic1");
2424
LL | | }
2525
| |_____^ help: try: `assert!(!b.is_empty(), "panic1");`
2626

2727
error: only a `panic!` in `if`-then statement
28-
--> $DIR/if_then_panic.rs:42:5
28+
--> $DIR/manual_assert.rs:42:5
2929
|
3030
LL | / if b.is_empty() && a.is_empty() {
3131
LL | | panic!("panic2");
3232
LL | | }
3333
| |_____^ help: try: `assert!(!(b.is_empty() && a.is_empty()), "panic2");`
3434

3535
error: only a `panic!` in `if`-then statement
36-
--> $DIR/if_then_panic.rs:45:5
36+
--> $DIR/manual_assert.rs:45:5
3737
|
3838
LL | / if a.is_empty() && !b.is_empty() {
3939
LL | | panic!("panic3");
4040
LL | | }
4141
| |_____^ help: try: `assert!(!(a.is_empty() && !b.is_empty()), "panic3");`
4242

4343
error: only a `panic!` in `if`-then statement
44-
--> $DIR/if_then_panic.rs:48:5
44+
--> $DIR/manual_assert.rs:48:5
4545
|
4646
LL | / if b.is_empty() || a.is_empty() {
4747
LL | | panic!("panic4");
4848
LL | | }
4949
| |_____^ help: try: `assert!(!(b.is_empty() || a.is_empty()), "panic4");`
5050

5151
error: only a `panic!` in `if`-then statement
52-
--> $DIR/if_then_panic.rs:51:5
52+
--> $DIR/manual_assert.rs:51:5
5353
|
5454
LL | / if a.is_empty() || !b.is_empty() {
5555
LL | | panic!("panic5");

tests/ui/ptr_arg.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
#![allow(
2-
unused,
3-
clippy::many_single_char_names,
4-
clippy::redundant_clone,
5-
clippy::if_then_panic
6-
)]
1+
#![allow(unused, clippy::many_single_char_names, clippy::redundant_clone)]
72
#![warn(clippy::ptr_arg)]
83

94
use std::borrow::Cow;

tests/ui/ptr_arg.stderr

+12-12
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
11
error: writing `&Vec<_>` instead of `&[_]` involves one more reference and cannot be used with non-Vec-based slices
2-
--> $DIR/ptr_arg.rs:12:14
2+
--> $DIR/ptr_arg.rs:7:14
33
|
44
LL | fn do_vec(x: &Vec<i64>) {
55
| ^^^^^^^^^ help: change this to: `&[i64]`
66
|
77
= note: `-D clippy::ptr-arg` implied by `-D warnings`
88

99
error: writing `&String` instead of `&str` involves a new object where a slice will do
10-
--> $DIR/ptr_arg.rs:21:14
10+
--> $DIR/ptr_arg.rs:16:14
1111
|
1212
LL | fn do_str(x: &String) {
1313
| ^^^^^^^ help: change this to: `&str`
1414

1515
error: writing `&PathBuf` instead of `&Path` involves a new object where a slice will do
16-
--> $DIR/ptr_arg.rs:30:15
16+
--> $DIR/ptr_arg.rs:25:15
1717
|
1818
LL | fn do_path(x: &PathBuf) {
1919
| ^^^^^^^^ help: change this to: `&Path`
2020

2121
error: writing `&Vec<_>` instead of `&[_]` involves one more reference and cannot be used with non-Vec-based slices
22-
--> $DIR/ptr_arg.rs:43:18
22+
--> $DIR/ptr_arg.rs:38:18
2323
|
2424
LL | fn do_vec(x: &Vec<i64>);
2525
| ^^^^^^^^^ help: change this to: `&[i64]`
2626

2727
error: writing `&Vec<_>` instead of `&[_]` involves one more reference and cannot be used with non-Vec-based slices
28-
--> $DIR/ptr_arg.rs:56:14
28+
--> $DIR/ptr_arg.rs:51:14
2929
|
3030
LL | fn cloned(x: &Vec<u8>) -> Vec<u8> {
3131
| ^^^^^^^^
@@ -44,7 +44,7 @@ LL | x.to_owned()
4444
|
4545

4646
error: writing `&String` instead of `&str` involves a new object where a slice will do
47-
--> $DIR/ptr_arg.rs:65:18
47+
--> $DIR/ptr_arg.rs:60:18
4848
|
4949
LL | fn str_cloned(x: &String) -> String {
5050
| ^^^^^^^
@@ -67,7 +67,7 @@ LL | x.to_string()
6767
|
6868

6969
error: writing `&PathBuf` instead of `&Path` involves a new object where a slice will do
70-
--> $DIR/ptr_arg.rs:73:19
70+
--> $DIR/ptr_arg.rs:68:19
7171
|
7272
LL | fn path_cloned(x: &PathBuf) -> PathBuf {
7373
| ^^^^^^^^
@@ -90,7 +90,7 @@ LL | x.to_path_buf()
9090
|
9191

9292
error: writing `&String` instead of `&str` involves a new object where a slice will do
93-
--> $DIR/ptr_arg.rs:81:44
93+
--> $DIR/ptr_arg.rs:76:44
9494
|
9595
LL | fn false_positive_capacity(x: &Vec<u8>, y: &String) {
9696
| ^^^^^^^
@@ -109,13 +109,13 @@ LL | let c = y;
109109
| ~
110110

111111
error: using a reference to `Cow` is not recommended
112-
--> $DIR/ptr_arg.rs:95:25
112+
--> $DIR/ptr_arg.rs:90:25
113113
|
114114
LL | fn test_cow_with_ref(c: &Cow<[i32]>) {}
115115
| ^^^^^^^^^^^ help: change this to: `&[i32]`
116116

117117
error: writing `&Vec<_>` instead of `&[_]` involves one more reference and cannot be used with non-Vec-based slices
118-
--> $DIR/ptr_arg.rs:148:21
118+
--> $DIR/ptr_arg.rs:143:21
119119
|
120120
LL | fn foo_vec(vec: &Vec<u8>) {
121121
| ^^^^^^^^
@@ -134,7 +134,7 @@ LL | let _ = vec.to_owned().clone();
134134
| ~~~~~~~~~~~~~~
135135

136136
error: writing `&PathBuf` instead of `&Path` involves a new object where a slice will do
137-
--> $DIR/ptr_arg.rs:153:23
137+
--> $DIR/ptr_arg.rs:148:23
138138
|
139139
LL | fn foo_path(path: &PathBuf) {
140140
| ^^^^^^^^
@@ -153,7 +153,7 @@ LL | let _ = path.to_path_buf().clone();
153153
| ~~~~~~~~~~~~~~~~~~
154154

155155
error: writing `&PathBuf` instead of `&Path` involves a new object where a slice will do
156-
--> $DIR/ptr_arg.rs:158:21
156+
--> $DIR/ptr_arg.rs:153:21
157157
|
158158
LL | fn foo_str(str: &PathBuf) {
159159
| ^^^^^^^^

0 commit comments

Comments
 (0)