@@ -2,6 +2,7 @@ use crate::{LateContext, LateLintPass, LintContext};
22use rustc_ast as ast;
33use rustc_errors:: { pluralize, Applicability } ;
44use rustc_hir as hir;
5+ use rustc_middle:: lint:: in_external_macro;
56use rustc_middle:: ty;
67use rustc_parse_format:: { ParseMode , Parser , Piece } ;
78use rustc_session:: lint:: FutureIncompatibilityReason ;
@@ -75,6 +76,11 @@ fn check_panic<'tcx>(cx: &LateContext<'tcx>, f: &'tcx hir::Expr<'tcx>, arg: &'tc
7576
7677 let ( span, panic, symbol_str) = panic_call ( cx, f) ;
7778
79+ if in_external_macro ( cx. sess ( ) , span) {
80+ // Nothing that can be done about it in the current crate.
81+ return ;
82+ }
83+
7884 // Find the span of the argument to `panic!()`, before expansion in the
7985 // case of `panic!(some_macro!())`.
8086 // We don't use source_callsite(), because this `panic!(..)` might itself
@@ -152,6 +158,13 @@ fn check_panic_str<'tcx>(
152158 return ;
153159 }
154160
161+ let ( span, _, _) = panic_call ( cx, f) ;
162+
163+ if in_external_macro ( cx. sess ( ) , span) && in_external_macro ( cx. sess ( ) , arg. span ) {
164+ // Nothing that can be done about it in the current crate.
165+ return ;
166+ }
167+
155168 let fmt_span = arg. span . source_callsite ( ) ;
156169
157170 let ( snippet, style) = match cx. sess ( ) . parse_sess . source_map ( ) . span_to_snippet ( fmt_span) {
@@ -167,8 +180,6 @@ fn check_panic_str<'tcx>(
167180 Parser :: new ( fmt. as_ref ( ) , style, snippet. clone ( ) , false , ParseMode :: Format ) ;
168181 let n_arguments = ( & mut fmt_parser) . filter ( |a| matches ! ( a, Piece :: NextArgument ( _) ) ) . count ( ) ;
169182
170- let ( span, _, _) = panic_call ( cx, f) ;
171-
172183 if n_arguments > 0 && fmt_parser. errors . is_empty ( ) {
173184 let arg_spans: Vec < _ > = match & fmt_parser. arg_places [ ..] {
174185 [ ] => vec ! [ fmt_span] ,
0 commit comments