@@ -25,6 +25,22 @@ declare_clippy_lint! {
25
25
"missing parameters in `panic!` calls"
26
26
}
27
27
28
+ declare_clippy_lint ! {
29
+ /// **What it does:** Checks for usage of `panic!`.
30
+ ///
31
+ /// **Why is this bad?** `panic!` will stop the execution of the executable
32
+ ///
33
+ /// **Known problems:** None.
34
+ ///
35
+ /// **Example:**
36
+ /// ```no_run
37
+ /// panic!("even with a good reason");
38
+ /// ```
39
+ pub PANIC ,
40
+ restriction,
41
+ "missing parameters in `panic!` calls"
42
+ }
43
+
28
44
declare_clippy_lint ! {
29
45
/// **What it does:** Checks for usage of `unimplemented!`.
30
46
///
@@ -41,7 +57,23 @@ declare_clippy_lint! {
41
57
"`unimplemented!` should not be present in production code"
42
58
}
43
59
44
- declare_lint_pass ! ( PanicUnimplemented => [ PANIC_PARAMS , UNIMPLEMENTED ] ) ;
60
+ declare_clippy_lint ! {
61
+ /// **What it does:** Checks for usage of `unreachable!`.
62
+ ///
63
+ /// **Why is this bad?** This macro can cause cause code to panics
64
+ ///
65
+ /// **Known problems:** None.
66
+ ///
67
+ /// **Example:**
68
+ /// ```no_run
69
+ /// unreachable!();
70
+ /// ```
71
+ pub UNREACHABLE ,
72
+ restriction,
73
+ "`unreachable!` should not be present in production code"
74
+ }
75
+
76
+ declare_lint_pass ! ( PanicUnimplemented => [ PANIC_PARAMS , UNIMPLEMENTED , UNREACHABLE ] ) ;
45
77
46
78
impl < ' a , ' tcx > LateLintPass < ' a , ' tcx > for PanicUnimplemented {
47
79
fn check_expr ( & mut self , cx : & LateContext < ' a , ' tcx > , expr : & ' tcx Expr ) {
@@ -55,7 +87,15 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for PanicUnimplemented {
55
87
let span = get_outer_span( expr) ;
56
88
span_lint( cx, UNIMPLEMENTED , span,
57
89
"`unimplemented` should not be present in production code" ) ;
58
- } else {
90
+ } else if is_expn_of( expr. span, "unreachable" ) . is_some( ) {
91
+ let span = get_outer_span( expr) ;
92
+ span_lint( cx, UNREACHABLE , span,
93
+ "`unreachable` should not be present in production code" ) ;
94
+ } else if is_expn_of( expr. span, "panic" ) . is_some( ) {
95
+ let span = get_outer_span( expr) ;
96
+ span_lint( cx, PANIC , span,
97
+ "`panic` should not be present in production code" ) ;
98
+ //} else {
59
99
match_panic( params, expr, cx) ;
60
100
}
61
101
}
0 commit comments