You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
use rustc_hir::intravisit::{self,FnKind,NestedVisitorMap,Visitor};
4
-
use rustc_hir::Expr;
3
+
use rustc_hir::intravisit::FnKind;
5
4
use rustc_lint::{LateContext,LateLintPass};
6
-
use rustc_middle::hir::map::Map;
7
5
use rustc_session::{declare_lint_pass, declare_tool_lint};
8
6
use rustc_span::{sym,Span};
9
7
10
8
declare_clippy_lint!{
11
-
/// **What it does:** Checks for usage of `panic!`, `unimplemented!`, `todo!` or `unreachable!` in a function of type result.
9
+
/// **What it does:** Checks for usage of `panic!`, `unimplemented!`, `todo!`, `unreachable!` or assertions in a function of type result.
12
10
///
13
-
/// **Why is this bad?** For some codebases, it is desirable for functions of type result to return an error instead of crashing. Hence unimplemented, panic and unreachable should be avoided.
11
+
/// **Why is this bad?** For some codebases, it is desirable for functions of type result to return an error instead of crashing. Hence panicking macros should be avoided.
14
12
///
15
-
/// **Known problems:** None.
13
+
/// **Known problems:** Functions called from a function returning a `Result` may invoke a panicking macro. This is not checked.
"used `unimplemented!()`, `unreachable!()`, `todo!()` or `panic!()` in a function that returns `Result`",
75
+
"used `unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertion in a function that returns `Result`",
82
76
move |diag| {
83
77
diag.help(
84
-
"`unimplemented!()`, `unreachable!()`, `todo!()` or `panic!()` should not be used in a function that returns `Result` as `Result` is expected to return an error instead of crashing",
78
+
"`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",
85
79
);
86
-
diag.span_note(panics.result,"return Err() instead of panicking");
80
+
diag.span_note(panics,"return Err() instead of panicking");
= note: `-D clippy::panic-in-result-fn` implied by `-D warnings`
11
-
= help: `unimplemented!()`, `unreachable!()`, `todo!()` or `panic!()` should not be used in a function that returns `Result` as `Result` is expected to return an error instead of crashing
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
12
12
note: return Err() instead of panicking
13
13
--> $DIR/panic_in_result_fn.rs:9:9
14
14
|
15
15
LL | panic!("error");
16
16
| ^^^^^^^^^^^^^^^^
17
17
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
18
18
19
-
error: used `unimplemented!()`, `unreachable!()`, `todo!()` or `panic!()` in a function that returns `Result`
19
+
error: used `unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertion in a function that returns `Result`
= help: `unimplemented!()`, `unreachable!()`, `todo!()` or `panic!()` should not be used in a function that returns `Result` as `Result` is expected to return an error instead of crashing
28
+
= 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
29
note: return Err() instead of panicking
30
30
--> $DIR/panic_in_result_fn.rs:14:9
31
31
|
32
32
LL | unimplemented!();
33
33
| ^^^^^^^^^^^^^^^^^
34
34
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
35
35
36
-
error: used `unimplemented!()`, `unreachable!()`, `todo!()` or `panic!()` in a function that returns `Result`
36
+
error: used `unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertion in a function that returns `Result`
= help: `unimplemented!()`, `unreachable!()`, `todo!()` or `panic!()` should not be used in a function that returns `Result` as `Result` is expected to return an error instead of crashing
45
+
= 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
46
note: return Err() instead of panicking
47
47
--> $DIR/panic_in_result_fn.rs:19:9
48
48
|
49
49
LL | unreachable!();
50
50
| ^^^^^^^^^^^^^^^
51
51
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
52
52
53
-
error: used `unimplemented!()`, `unreachable!()`, `todo!()` or `panic!()` in a function that returns `Result`
53
+
error: used `unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertion in a function that returns `Result`
= help: `unimplemented!()`, `unreachable!()`, `todo!()` or `panic!()` should not be used in a function that returns `Result` as `Result` is expected to return an error instead of crashing
62
+
= 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
63
63
note: return Err() instead of panicking
64
64
--> $DIR/panic_in_result_fn.rs:24:9
65
65
|
66
66
LL | todo!("Finish this");
67
67
| ^^^^^^^^^^^^^^^^^^^^^
68
68
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
69
69
70
-
error: used `unimplemented!()`, `unreachable!()`, `todo!()` or `panic!()` in a function that returns `Result`
70
+
error: used `unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertion in a function that returns `Result`
= help: `unimplemented!()`, `unreachable!()`, `todo!()` or `panic!()` should not be used in a function that returns `Result` as `Result` is expected to return an error instead of crashing
79
+
= 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
80
80
note: return Err() instead of panicking
81
81
--> $DIR/panic_in_result_fn.rs:55:5
82
82
|
83
83
LL | panic!("error");
84
84
| ^^^^^^^^^^^^^^^^
85
85
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
86
86
87
-
error: used `unimplemented!()`, `unreachable!()`, `todo!()` or `panic!()` in a function that returns `Result`
87
+
error: used `unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertion in a function that returns `Result`
88
88
--> $DIR/panic_in_result_fn.rs:68:1
89
89
|
90
90
LL | / fn main() -> Result<(), String> {
@@ -93,7 +93,7 @@ LL | | Ok(())
93
93
LL | | }
94
94
| |_^
95
95
|
96
-
= help: `unimplemented!()`, `unreachable!()`, `todo!()` or `panic!()` should not be used in a function that returns `Result` as `Result` is expected to return an error instead of crashing
96
+
= 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
= note: `-D clippy::panic-in-result-fn` implied by `-D warnings`
12
+
= 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
13
+
note: return Err() instead of panicking
14
+
--> $DIR/panic_in_result_fn_assertions.rs:9:9
15
+
|
16
+
LL | assert!(x == 5, "wrong argument");
17
+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
18
+
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
19
+
20
+
error: used `unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertion in a function that returns `Result`
= 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
31
+
note: return Err() instead of panicking
32
+
--> $DIR/panic_in_result_fn_assertions.rs:15:9
33
+
|
34
+
LL | assert_eq!(x, 5);
35
+
| ^^^^^^^^^^^^^^^^^
36
+
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
37
+
38
+
error: used `unimplemented!()`, `unreachable!()`, `todo!()`, `panic!()` or assertion in a function that returns `Result`
= 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
49
+
note: return Err() instead of panicking
50
+
--> $DIR/panic_in_result_fn_assertions.rs:21:9
51
+
|
52
+
LL | assert_ne!(x, 1);
53
+
| ^^^^^^^^^^^^^^^^^
54
+
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
0 commit comments