about summary refs log tree commit diff
diff options
context:
space:
mode:
authorGary Guo <gary@garyguo.net>2021-10-18 00:41:57 +0100
committerGary Guo <gary@garyguo.net>2022-01-29 13:52:19 +0000
commit4119f60c1f422d84fb53bb7d3e73bfdfc2b09add (patch)
treec841e73ebcab1ce36318f96e660f0b4e6f1f8bf1
parent82f613ee3b12a6a90bd9e99fbbab947674d6ec7a (diff)
downloadrust-4119f60c1f422d84fb53bb7d3e73bfdfc2b09add.tar.gz
rust-4119f60c1f422d84fb53bb7d3e73bfdfc2b09add.zip
Create `core::fmt::ArgumentV1` with generics instead of fn pointer
-rw-r--r--clippy_utils/src/macros.rs22
1 files changed, 16 insertions, 6 deletions
diff --git a/clippy_utils/src/macros.rs b/clippy_utils/src/macros.rs
index b7a242cf90a..a75f6b86a9b 100644
--- a/clippy_utils/src/macros.rs
+++ b/clippy_utils/src/macros.rs
@@ -339,15 +339,13 @@ impl<'tcx> FormatArgsExpn<'tcx> {
         expr_visitor_no_bodies(|e| {
             // if we're still inside of the macro definition...
             if e.span.ctxt() == expr.span.ctxt() {
-                // ArgumnetV1::new(<value>, <format_trait>::fmt)
+                // ArgumnetV1::new_<format_trait>(<value>)
                 if_chain! {
-                    if let ExprKind::Call(callee, [val, fmt_path]) = e.kind;
+                    if let ExprKind::Call(callee, [val]) = e.kind;
                     if let ExprKind::Path(QPath::TypeRelative(ty, seg)) = callee.kind;
-                    if seg.ident.name == sym::new;
                     if let hir::TyKind::Path(QPath::Resolved(_, path)) = ty.kind;
                     if path.segments.last().unwrap().ident.name == sym::ArgumentV1;
-                    if let ExprKind::Path(QPath::Resolved(_, path)) = fmt_path.kind;
-                    if let [.., fmt_trait, _fmt] = path.segments;
+                    if seg.ident.name.as_str().starts_with("new_");
                     then {
                         let val_idx = if_chain! {
                             if val.span.ctxt() == expr.span.ctxt();
@@ -361,7 +359,19 @@ impl<'tcx> FormatArgsExpn<'tcx> {
                                 formatters.len()
                             }
                         };
-                        formatters.push((val_idx, fmt_trait.ident.name));
+                        let fmt_trait = match seg.ident.name.as_str() {
+                            "new_display" => "Display",
+                            "new_debug" => "Debug",
+                            "new_lower_exp" => "LowerExp",
+                            "new_upper_exp" => "UpperExp",
+                            "new_octal" => "Octal",
+                            "new_pointer" => "Pointer",
+                            "new_binary" => "Binary",
+                            "new_lower_hex" => "LowerHex",
+                            "new_upper_hex" => "UpperHex",
+                            _ => unreachable!(),
+                        };
+                        formatters.push((val_idx, Symbol::intern(fmt_trait)));
                     }
                 }
                 if let ExprKind::Struct(QPath::Resolved(_, path), ..) = e.kind {