1
1
use clippy_utils:: diagnostics:: { span_lint_and_sugg, span_lint_and_then} ;
2
2
use 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 } ;
4
4
use clippy_utils:: source:: snippet_opt;
5
5
use clippy_utils:: ty:: implements_trait;
6
6
use clippy_utils:: { is_diag_trait_item, meets_msrv, msrvs} ;
@@ -13,6 +13,8 @@ use rustc_middle::ty::adjustment::{Adjust, Adjustment};
13
13
use rustc_middle:: ty:: Ty ;
14
14
use rustc_semver:: RustcVersion ;
15
15
use rustc_session:: { declare_tool_lint, impl_lint_pass} ;
16
+ use rustc_span:: def_id:: DefId ;
17
+ use rustc_span:: edition:: Edition :: Edition2021 ;
16
18
use rustc_span:: { sym, ExpnData , ExpnKind , Span , Symbol } ;
17
19
18
20
declare_clippy_lint ! {
@@ -149,7 +151,7 @@ impl<'tcx> LateLintPass<'tcx> for FormatArgs {
149
151
check_to_string_in_format_args( cx, name, arg. param. value) ;
150
152
}
151
153
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 ) ;
153
155
}
154
156
}
155
157
}
@@ -158,10 +160,14 @@ impl<'tcx> LateLintPass<'tcx> for FormatArgs {
158
160
extract_msrv_attr ! ( LateContext ) ;
159
161
}
160
162
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 ) {
162
164
if args. format_string . span . from_expansion ( ) {
163
165
return ;
164
166
}
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
+ }
165
171
166
172
let mut fixes = Vec :: new ( ) ;
167
173
// If any of the arguments are referenced by an index number,
0 commit comments