@@ -49,9 +49,11 @@ impl<'tcx> LateLintPass<'tcx> for NonPanicFmt {
49
49
fn check_expr ( & mut self , cx : & LateContext < ' tcx > , expr : & ' tcx hir:: Expr < ' tcx > ) {
50
50
if let hir:: ExprKind :: Call ( f, [ arg] ) = & expr. kind {
51
51
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
+
52
54
if Some ( def_id) == cx. tcx . lang_items ( ) . begin_panic_fn ( )
53
55
|| 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)
55
57
{
56
58
if let Some ( id) = f. span . ctxt ( ) . outer_expn_data ( ) . macro_def_id {
57
59
if matches ! (
@@ -61,6 +63,22 @@ impl<'tcx> LateLintPass<'tcx> for NonPanicFmt {
61
63
check_panic ( cx, f, arg) ;
62
64
}
63
65
}
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
+ }
64
82
}
65
83
}
66
84
}
@@ -85,8 +103,8 @@ fn check_panic<'tcx>(cx: &LateContext<'tcx>, f: &'tcx hir::Expr<'tcx>, arg: &'tc
85
103
return ;
86
104
}
87
105
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!())` .
90
108
// We don't use source_callsite(), because this `panic!(..)` might itself
91
109
// be expanded from another macro, in which case we want to stop at that
92
110
// expansion.
@@ -319,6 +337,7 @@ fn panic_call<'tcx>(cx: &LateContext<'tcx>, f: &'tcx hir::Expr<'tcx>) -> (Span,
319
337
| sym:: std_panic_macro
320
338
| sym:: assert_macro
321
339
| sym:: debug_assert_macro
340
+ | sym:: unreachable_macro
322
341
) {
323
342
break ;
324
343
}
0 commit comments