11use clippy_utils:: diagnostics:: { span_lint_and_sugg, span_lint_and_then} ;
22use clippy_utils:: macros:: FormatParamKind :: { Implicit , Named , Numbered , Starred } ;
3- use clippy_utils:: macros:: { is_format_macro, FormatArgsExpn , FormatParam , FormatParamUsage } ;
3+ use clippy_utils:: macros:: { is_format_macro, is_panic , FormatArgsExpn , FormatParam , FormatParamUsage } ;
44use clippy_utils:: source:: snippet_opt;
55use clippy_utils:: ty:: implements_trait;
66use clippy_utils:: { is_diag_trait_item, meets_msrv, msrvs} ;
@@ -13,6 +13,8 @@ use rustc_middle::ty::adjustment::{Adjust, Adjustment};
1313use rustc_middle:: ty:: Ty ;
1414use rustc_semver:: RustcVersion ;
1515use rustc_session:: { declare_tool_lint, impl_lint_pass} ;
16+ use rustc_span:: def_id:: DefId ;
17+ use rustc_span:: edition:: Edition :: Edition2021 ;
1618use rustc_span:: { sym, ExpnData , ExpnKind , Span , Symbol } ;
1719
1820declare_clippy_lint ! {
@@ -149,7 +151,7 @@ impl<'tcx> LateLintPass<'tcx> for FormatArgs {
149151 check_to_string_in_format_args( cx, name, arg. param. value) ;
150152 }
151153 if meets_msrv( self . msrv, msrvs:: FORMAT_ARGS_CAPTURE ) {
152- check_uninlined_args( cx, & format_args, outermost_expn_data. call_site) ;
154+ check_uninlined_args( cx, & format_args, outermost_expn_data. call_site, macro_def_id ) ;
153155 }
154156 }
155157 }
@@ -158,10 +160,14 @@ impl<'tcx> LateLintPass<'tcx> for FormatArgs {
158160 extract_msrv_attr ! ( LateContext ) ;
159161}
160162
161- fn check_uninlined_args ( cx : & LateContext < ' _ > , args : & FormatArgsExpn < ' _ > , call_site : Span ) {
163+ fn check_uninlined_args ( cx : & LateContext < ' _ > , args : & FormatArgsExpn < ' _ > , call_site : Span , def_id : DefId ) {
162164 if args. format_string . span . from_expansion ( ) {
163165 return ;
164166 }
167+ if call_site. edition ( ) < Edition2021 && is_panic ( cx, def_id) {
168+ // panic! before 2021 edition considers a single string argument as non-format
169+ return ;
170+ }
165171
166172 let mut fixes = Vec :: new ( ) ;
167173 // If any of the arguments are referenced by an index number,
0 commit comments