@@ -25,6 +25,22 @@ declare_clippy_lint! {
2525 "missing parameters in `panic!` calls"
2626}
2727
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+
2844declare_clippy_lint ! {
2945 /// **What it does:** Checks for usage of `unimplemented!`.
3046 ///
@@ -41,7 +57,23 @@ declare_clippy_lint! {
4157 "`unimplemented!` should not be present in production code"
4258}
4359
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 ] ) ;
4577
4678impl < ' a , ' tcx > LateLintPass < ' a , ' tcx > for PanicUnimplemented {
4779 fn check_expr ( & mut self , cx : & LateContext < ' a , ' tcx > , expr : & ' tcx Expr ) {
@@ -55,7 +87,15 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for PanicUnimplemented {
5587 let span = get_outer_span( expr) ;
5688 span_lint( cx, UNIMPLEMENTED , span,
5789 "`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 {
5999 match_panic( params, expr, cx) ;
60100 }
61101 }
0 commit comments