@@ -49,9 +49,11 @@ impl<'tcx> LateLintPass<'tcx> for NonPanicFmt {
4949 fn check_expr ( & mut self , cx : & LateContext < ' tcx > , expr : & ' tcx hir:: Expr < ' tcx > ) {
5050 if let hir:: ExprKind :: Call ( f, [ arg] ) = & expr. kind {
5151 if let & ty:: FnDef ( def_id, _) = cx. typeck_results ( ) . expr_ty ( f) . kind ( ) {
52+ let f_diagnostic_name = cx. tcx . get_diagnostic_name ( def_id) ;
53+
5254 if Some ( def_id) == cx. tcx . lang_items ( ) . begin_panic_fn ( )
5355 || Some ( def_id) == cx. tcx . lang_items ( ) . panic_fn ( )
54- || Some ( def_id ) == cx . tcx . lang_items ( ) . panic_str ( )
56+ || f_diagnostic_name == Some ( sym :: panic_str)
5557 {
5658 if let Some ( id) = f. span . ctxt ( ) . outer_expn_data ( ) . macro_def_id {
5759 if matches ! (
@@ -61,6 +63,22 @@ impl<'tcx> LateLintPass<'tcx> for NonPanicFmt {
6163 check_panic ( cx, f, arg) ;
6264 }
6365 }
66+ } else if f_diagnostic_name == Some ( sym:: unreachable_display) {
67+ if let Some ( id) = f. span . ctxt ( ) . outer_expn_data ( ) . macro_def_id {
68+ if cx. tcx . is_diagnostic_item ( sym:: unreachable_2015_macro, id) {
69+ check_panic (
70+ cx,
71+ f,
72+ // This is safe because we checked above that the callee is indeed
73+ // unreachable_display
74+ match & arg. kind {
75+ // Get the borrowed arg not the borrow
76+ hir:: ExprKind :: AddrOf ( ast:: BorrowKind :: Ref , _, arg) => arg,
77+ _ => bug ! ( "call to unreachable_display without borrow" ) ,
78+ } ,
79+ ) ;
80+ }
81+ }
6482 }
6583 }
6684 }
@@ -85,8 +103,8 @@ fn check_panic<'tcx>(cx: &LateContext<'tcx>, f: &'tcx hir::Expr<'tcx>, arg: &'tc
85103 return ;
86104 }
87105
88- // Find the span of the argument to `panic!()`, before expansion in the
89- // case of `panic!(some_macro!())`.
106+ // Find the span of the argument to `panic!()` or `unreachable!` , before expansion in the
107+ // case of `panic!(some_macro!())` or `unreachable!(some_macro!())` .
90108 // We don't use source_callsite(), because this `panic!(..)` might itself
91109 // be expanded from another macro, in which case we want to stop at that
92110 // expansion.
@@ -319,6 +337,7 @@ fn panic_call<'tcx>(cx: &LateContext<'tcx>, f: &'tcx hir::Expr<'tcx>) -> (Span,
319337 | sym:: std_panic_macro
320338 | sym:: assert_macro
321339 | sym:: debug_assert_macro
340+ | sym:: unreachable_macro
322341 ) {
323342 break ;
324343 }
0 commit comments