@@ -2,6 +2,7 @@ use crate::{LateContext, LateLintPass, LintContext};
2
2
use rustc_ast as ast;
3
3
use rustc_errors:: { pluralize, Applicability } ;
4
4
use rustc_hir as hir;
5
+ use rustc_middle:: lint:: in_external_macro;
5
6
use rustc_middle:: ty;
6
7
use rustc_parse_format:: { ParseMode , Parser , Piece } ;
7
8
use rustc_session:: lint:: FutureIncompatibilityReason ;
@@ -75,6 +76,11 @@ fn check_panic<'tcx>(cx: &LateContext<'tcx>, f: &'tcx hir::Expr<'tcx>, arg: &'tc
75
76
76
77
let ( span, panic, symbol_str) = panic_call ( cx, f) ;
77
78
79
+ if in_external_macro ( cx. sess ( ) , span) {
80
+ // Nothing that can be done about it in the current crate.
81
+ return ;
82
+ }
83
+
78
84
// Find the span of the argument to `panic!()`, before expansion in the
79
85
// case of `panic!(some_macro!())`.
80
86
// We don't use source_callsite(), because this `panic!(..)` might itself
@@ -152,6 +158,13 @@ fn check_panic_str<'tcx>(
152
158
return ;
153
159
}
154
160
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
+
155
168
let fmt_span = arg. span . source_callsite ( ) ;
156
169
157
170
let ( snippet, style) = match cx. sess ( ) . parse_sess . source_map ( ) . span_to_snippet ( fmt_span) {
@@ -167,8 +180,6 @@ fn check_panic_str<'tcx>(
167
180
Parser :: new ( fmt. as_ref ( ) , style, snippet. clone ( ) , false , ParseMode :: Format ) ;
168
181
let n_arguments = ( & mut fmt_parser) . filter ( |a| matches ! ( a, Piece :: NextArgument ( _) ) ) . count ( ) ;
169
182
170
- let ( span, _, _) = panic_call ( cx, f) ;
171
-
172
183
if n_arguments > 0 && fmt_parser. errors . is_empty ( ) {
173
184
let arg_spans: Vec < _ > = match & fmt_parser. arg_places [ ..] {
174
185
[ ] => vec ! [ fmt_span] ,
0 commit comments