X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=compiler%2Frustc_lint%2Fsrc%2Fnon_fmt_panic.rs;h=ec53625f10525014264c53f0dc895ec7c858aa19;hb=5a19ffe1c2b99d9e09706cc286aad1ec0868eddb;hp=a32caf1bc433df1cbf94ffa4f3d7322f2ff43ed5;hpb=25dda3647ea42d1b64aca6e5584faff0d8a38dbc;p=rust.git diff --git a/compiler/rustc_lint/src/non_fmt_panic.rs b/compiler/rustc_lint/src/non_fmt_panic.rs index a32caf1bc43..ec53625f105 100644 --- a/compiler/rustc_lint/src/non_fmt_panic.rs +++ b/compiler/rustc_lint/src/non_fmt_panic.rs @@ -2,6 +2,7 @@ use rustc_ast as ast; use rustc_errors::{pluralize, Applicability}; use rustc_hir as hir; +use rustc_middle::lint::in_external_macro; use rustc_middle::ty; use rustc_parse_format::{ParseMode, Parser, Piece}; use rustc_session::lint::FutureIncompatibilityReason; @@ -75,6 +76,11 @@ fn check_panic<'tcx>(cx: &LateContext<'tcx>, f: &'tcx hir::Expr<'tcx>, arg: &'tc let (span, panic, symbol_str) = panic_call(cx, f); + if in_external_macro(cx.sess(), span) { + // Nothing that can be done about it in the current crate. + return; + } + // Find the span of the argument to `panic!()`, before expansion in the // case of `panic!(some_macro!())`. // We don't use source_callsite(), because this `panic!(..)` might itself @@ -152,6 +158,13 @@ fn check_panic_str<'tcx>( return; } + let (span, _, _) = panic_call(cx, f); + + if in_external_macro(cx.sess(), span) && in_external_macro(cx.sess(), arg.span) { + // Nothing that can be done about it in the current crate. + return; + } + let fmt_span = arg.span.source_callsite(); let (snippet, style) = match cx.sess().parse_sess.source_map().span_to_snippet(fmt_span) { @@ -167,8 +180,6 @@ fn check_panic_str<'tcx>( Parser::new(fmt.as_ref(), style, snippet.clone(), false, ParseMode::Format); let n_arguments = (&mut fmt_parser).filter(|a| matches!(a, Piece::NextArgument(_))).count(); - let (span, _, _) = panic_call(cx, f); - if n_arguments > 0 && fmt_parser.errors.is_empty() { let arg_spans: Vec<_> = match &fmt_parser.arg_places[..] { [] => vec![fmt_span],