Skip to content

Commit c49c177

Browse files
committed
[panic_in_result_fn] remove todo!, unimplemented!, unreachable!
This commit fixes #11025 by removing checks for `todo!`, `unimplemented!` and `unreachable!`. Signed-off-by: Panagiotis Foliadis <[email protected]>
1 parent 26edd5a commit c49c177

File tree

3 files changed

+16
-80
lines changed

3 files changed

+16
-80
lines changed

clippy_lints/src/panic_in_result_fn.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use rustc_span::{sym, Span};
1313

1414
declare_clippy_lint! {
1515
/// ### What it does
16-
/// Checks for usage of `panic!`, `unimplemented!`, `todo!`, `unreachable!` or assertions in a function of type result.
16+
/// Checks for usage of `panic!` or assertions in a function of type result.
1717
///
1818
/// ### Why is this bad?
1919
/// For some codebases, it is desirable for functions of type result to return an error instead of crashing. Hence panicking macros should be avoided.
@@ -37,7 +37,7 @@ declare_clippy_lint! {
3737
#[clippy::version = "1.48.0"]
3838
pub PANIC_IN_RESULT_FN,
3939
restriction,
40-
"functions of type `Result<..>` that contain `panic!()`, `todo!()`, `unreachable()`, `unimplemented()` or assertion"
40+
"functions of type `Result<..>` that contain `panic!()` or assertion"
4141
}
4242

4343
declare_lint_pass!(PanicInResultFn => [PANIC_IN_RESULT_FN]);
@@ -70,7 +70,7 @@ fn lint_impl_body<'tcx>(cx: &LateContext<'tcx>, impl_span: Span, body: &'tcx hir
7070
};
7171
if matches!(
7272
cx.tcx.item_name(macro_call.def_id).as_str(),
73-
"unimplemented" | "unreachable" | "panic" | "todo" | "assert" | "assert_eq" | "assert_ne"
73+
"panic" | "assert" | "assert_eq" | "assert_ne"
7474
) {
7575
panics.push(macro_call.span);
7676
ControlFlow::Continue(Descend::No)
@@ -83,10 +83,10 @@ fn lint_impl_body<'tcx>(cx: &LateContext<'tcx>, impl_span: Span, body: &'tcx hir
8383
cx,
8484
PANIC_IN_RESULT_FN,
8585
impl_span,
86-
"used `unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertion in a function that returns `Result`",
86+
"used `panic!()` or assertion in a function that returns `Result`",
8787
move |diag| {
8888
diag.help(
89-
"`unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertions should not be used in a function that returns `Result` as `Result` is expected to return an error instead of crashing",
89+
"`panic!()` or assertions should not be used in a function that returns `Result` as `Result` is expected to return an error instead of crashing",
9090
);
9191
diag.span_note(panics, "return Err() instead of panicking");
9292
},

tests/ui/panic_in_result_fn.stderr

+5-69
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: used `unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertion in a function that returns `Result`
1+
error: used `panic!()` or assertion in a function that returns `Result`
22
--> $DIR/panic_in_result_fn.rs:6:5
33
|
44
LL | / fn result_with_panic() -> Result<bool, String> // should emit lint
@@ -7,63 +7,15 @@ LL | | panic!("error");
77
LL | | }
88
| |_____^
99
|
10-
= help: `unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertions should not be used in a function that returns `Result` as `Result` is expected to return an error instead of crashing
10+
= help: `panic!()` or assertions should not be used in a function that returns `Result` as `Result` is expected to return an error instead of crashing
1111
note: return Err() instead of panicking
1212
--> $DIR/panic_in_result_fn.rs:8:9
1313
|
1414
LL | panic!("error");
1515
| ^^^^^^^^^^^^^^^
1616
= note: `-D clippy::panic-in-result-fn` implied by `-D warnings`
1717

18-
error: used `unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertion in a function that returns `Result`
19-
--> $DIR/panic_in_result_fn.rs:11:5
20-
|
21-
LL | / fn result_with_unimplemented() -> Result<bool, String> // should emit lint
22-
LL | | {
23-
LL | | unimplemented!();
24-
LL | | }
25-
| |_____^
26-
|
27-
= help: `unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertions should not be used in a function that returns `Result` as `Result` is expected to return an error instead of crashing
28-
note: return Err() instead of panicking
29-
--> $DIR/panic_in_result_fn.rs:13:9
30-
|
31-
LL | unimplemented!();
32-
| ^^^^^^^^^^^^^^^^
33-
34-
error: used `unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertion in a function that returns `Result`
35-
--> $DIR/panic_in_result_fn.rs:16:5
36-
|
37-
LL | / fn result_with_unreachable() -> Result<bool, String> // should emit lint
38-
LL | | {
39-
LL | | unreachable!();
40-
LL | | }
41-
| |_____^
42-
|
43-
= help: `unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertions should not be used in a function that returns `Result` as `Result` is expected to return an error instead of crashing
44-
note: return Err() instead of panicking
45-
--> $DIR/panic_in_result_fn.rs:18:9
46-
|
47-
LL | unreachable!();
48-
| ^^^^^^^^^^^^^^
49-
50-
error: used `unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertion in a function that returns `Result`
51-
--> $DIR/panic_in_result_fn.rs:21:5
52-
|
53-
LL | / fn result_with_todo() -> Result<bool, String> // should emit lint
54-
LL | | {
55-
LL | | todo!("Finish this");
56-
LL | | }
57-
| |_____^
58-
|
59-
= help: `unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertions should not be used in a function that returns `Result` as `Result` is expected to return an error instead of crashing
60-
note: return Err() instead of panicking
61-
--> $DIR/panic_in_result_fn.rs:23:9
62-
|
63-
LL | todo!("Finish this");
64-
| ^^^^^^^^^^^^^^^^^^^^
65-
66-
error: used `unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertion in a function that returns `Result`
18+
error: used `panic!()` or assertion in a function that returns `Result`
6719
--> $DIR/panic_in_result_fn.rs:52:1
6820
|
6921
LL | / fn function_result_with_panic() -> Result<bool, String> // should emit lint
@@ -72,28 +24,12 @@ LL | | panic!("error");
7224
LL | | }
7325
| |_^
7426
|
75-
= help: `unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertions should not be used in a function that returns `Result` as `Result` is expected to return an error instead of crashing
27+
= help: `panic!()` or assertions should not be used in a function that returns `Result` as `Result` is expected to return an error instead of crashing
7628
note: return Err() instead of panicking
7729
--> $DIR/panic_in_result_fn.rs:54:5
7830
|
7931
LL | panic!("error");
8032
| ^^^^^^^^^^^^^^^
8133

82-
error: used `unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertion in a function that returns `Result`
83-
--> $DIR/panic_in_result_fn.rs:67:1
84-
|
85-
LL | / fn main() -> Result<(), String> {
86-
LL | | todo!("finish main method");
87-
LL | | Ok(())
88-
LL | | }
89-
| |_^
90-
|
91-
= help: `unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertions should not be used in a function that returns `Result` as `Result` is expected to return an error instead of crashing
92-
note: return Err() instead of panicking
93-
--> $DIR/panic_in_result_fn.rs:68:5
94-
|
95-
LL | todo!("finish main method");
96-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
97-
98-
error: aborting due to 6 previous errors
34+
error: aborting due to 2 previous errors
9935

tests/ui/panic_in_result_fn_assertions.stderr

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: used `unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertion in a function that returns `Result`
1+
error: used `panic!()` or assertion in a function that returns `Result`
22
--> $DIR/panic_in_result_fn_assertions.rs:7:5
33
|
44
LL | / fn result_with_assert_with_message(x: i32) -> Result<bool, String> // should emit lint
@@ -8,15 +8,15 @@ LL | | Ok(true)
88
LL | | }
99
| |_____^
1010
|
11-
= help: `unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertions should not be used in a function that returns `Result` as `Result` is expected to return an error instead of crashing
11+
= help: `panic!()` or assertions should not be used in a function that returns `Result` as `Result` is expected to return an error instead of crashing
1212
note: return Err() instead of panicking
1313
--> $DIR/panic_in_result_fn_assertions.rs:9:9
1414
|
1515
LL | assert!(x == 5, "wrong argument");
1616
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1717
= note: `-D clippy::panic-in-result-fn` implied by `-D warnings`
1818

19-
error: used `unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertion in a function that returns `Result`
19+
error: used `panic!()` or assertion in a function that returns `Result`
2020
--> $DIR/panic_in_result_fn_assertions.rs:13:5
2121
|
2222
LL | / fn result_with_assert_eq(x: i32) -> Result<bool, String> // should emit lint
@@ -26,14 +26,14 @@ LL | | Ok(true)
2626
LL | | }
2727
| |_____^
2828
|
29-
= help: `unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertions should not be used in a function that returns `Result` as `Result` is expected to return an error instead of crashing
29+
= help: `panic!()` or assertions should not be used in a function that returns `Result` as `Result` is expected to return an error instead of crashing
3030
note: return Err() instead of panicking
3131
--> $DIR/panic_in_result_fn_assertions.rs:15:9
3232
|
3333
LL | assert_eq!(x, 5);
3434
| ^^^^^^^^^^^^^^^^
3535

36-
error: used `unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertion in a function that returns `Result`
36+
error: used `panic!()` or assertion in a function that returns `Result`
3737
--> $DIR/panic_in_result_fn_assertions.rs:19:5
3838
|
3939
LL | / fn result_with_assert_ne(x: i32) -> Result<bool, String> // should emit lint
@@ -43,7 +43,7 @@ LL | | Ok(true)
4343
LL | | }
4444
| |_____^
4545
|
46-
= help: `unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertions should not be used in a function that returns `Result` as `Result` is expected to return an error instead of crashing
46+
= help: `panic!()` or assertions should not be used in a function that returns `Result` as `Result` is expected to return an error instead of crashing
4747
note: return Err() instead of panicking
4848
--> $DIR/panic_in_result_fn_assertions.rs:21:9
4949
|

0 commit comments

Comments
 (0)