diff options
| author | bors <bors@rust-lang.org> | 2023-09-14 17:28:51 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-09-14 17:28:51 +0000 |
| commit | b27fc10aa890a8cbc00f7d361ffd58da40dcd6ea (patch) | |
| tree | 3e40bb0343b0c4989680abdf61d03371a73f5a5e /clippy_lints/src/format_args.rs | |
| parent | 0273ed3afd1cb032655aef0019c448b9a6950731 (diff) | |
| parent | c29de92d85f22bdc8814e87e4d4ee9f46d3c679e (diff) | |
| download | rust-b27fc10aa890a8cbc00f7d361ffd58da40dcd6ea.tar.gz rust-b27fc10aa890a8cbc00f7d361ffd58da40dcd6ea.zip | |
Auto merge of #11444 - Alexendoo:find-format-args-lifetime-crimes, r=flip1995
Return a value from find_format_args instead of using a callback r? `@flip1995` changelog: none
Diffstat (limited to 'clippy_lints/src/format_args.rs')
| -rw-r--r-- | clippy_lints/src/format_args.rs | 20 |
1 files changed, 8 insertions, 12 deletions
diff --git a/clippy_lints/src/format_args.rs b/clippy_lints/src/format_args.rs index 01c714c414b..39abf5c2def 100644 --- a/clippy_lints/src/format_args.rs +++ b/clippy_lints/src/format_args.rs @@ -186,15 +186,10 @@ impl FormatArgs { impl<'tcx> LateLintPass<'tcx> for FormatArgs { fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) { - let Some(macro_call) = root_macro_call_first_node(cx, expr) else { - return; - }; - if !is_format_macro(cx, macro_call.def_id) { - return; - } - let name = cx.tcx.item_name(macro_call.def_id); - - find_format_args(cx, expr, macro_call.expn, |format_args| { + if let Some(macro_call) = root_macro_call_first_node(cx, expr) + && is_format_macro(cx, macro_call.def_id) + && let Some(format_args) = find_format_args(cx, expr, macro_call.expn) + { for piece in &format_args.template { if let FormatArgsPiece::Placeholder(placeholder) = piece && let Ok(index) = placeholder.argument.index @@ -206,12 +201,13 @@ impl<'tcx> LateLintPass<'tcx> for FormatArgs { if placeholder.format_trait != FormatTrait::Display || placeholder.format_options != FormatOptions::default() - || is_aliased(format_args, index) + || is_aliased(&format_args, index) { continue; } if let Ok(arg_hir_expr) = arg_expr { + let name = cx.tcx.item_name(macro_call.def_id); check_format_in_format_args(cx, macro_call.span, name, arg_hir_expr); check_to_string_in_format_args(cx, name, arg_hir_expr); } @@ -219,9 +215,9 @@ impl<'tcx> LateLintPass<'tcx> for FormatArgs { } if self.msrv.meets(msrvs::FORMAT_ARGS_CAPTURE) { - check_uninlined_args(cx, format_args, macro_call.span, macro_call.def_id, self.ignore_mixed); + check_uninlined_args(cx, &format_args, macro_call.span, macro_call.def_id, self.ignore_mixed); } - }); + } } extract_msrv_attr!(LateContext); |
