Skip to content

Commit 4119f60

Browse files
committed
Create core::fmt::ArgumentV1 with generics instead of fn pointer
1 parent 82f613e commit 4119f60

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

clippy_utils/src/macros.rs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -339,15 +339,13 @@ impl<'tcx> FormatArgsExpn<'tcx> {
339339
expr_visitor_no_bodies(|e| {
340340
// if we're still inside of the macro definition...
341341
if e.span.ctxt() == expr.span.ctxt() {
342-
// ArgumnetV1::new(<value>, <format_trait>::fmt)
342+
// ArgumnetV1::new_<format_trait>(<value>)
343343
if_chain! {
344-
if let ExprKind::Call(callee, [val, fmt_path]) = e.kind;
344+
if let ExprKind::Call(callee, [val]) = e.kind;
345345
if let ExprKind::Path(QPath::TypeRelative(ty, seg)) = callee.kind;
346-
if seg.ident.name == sym::new;
347346
if let hir::TyKind::Path(QPath::Resolved(_, path)) = ty.kind;
348347
if path.segments.last().unwrap().ident.name == sym::ArgumentV1;
349-
if let ExprKind::Path(QPath::Resolved(_, path)) = fmt_path.kind;
350-
if let [.., fmt_trait, _fmt] = path.segments;
348+
if seg.ident.name.as_str().starts_with("new_");
351349
then {
352350
let val_idx = if_chain! {
353351
if val.span.ctxt() == expr.span.ctxt();
@@ -361,7 +359,19 @@ impl<'tcx> FormatArgsExpn<'tcx> {
361359
formatters.len()
362360
}
363361
};
364-
formatters.push((val_idx, fmt_trait.ident.name));
362+
let fmt_trait = match seg.ident.name.as_str() {
363+
"new_display" => "Display",
364+
"new_debug" => "Debug",
365+
"new_lower_exp" => "LowerExp",
366+
"new_upper_exp" => "UpperExp",
367+
"new_octal" => "Octal",
368+
"new_pointer" => "Pointer",
369+
"new_binary" => "Binary",
370+
"new_lower_hex" => "LowerHex",
371+
"new_upper_hex" => "UpperHex",
372+
_ => unreachable!(),
373+
};
374+
formatters.push((val_idx, Symbol::intern(fmt_trait)));
365375
}
366376
}
367377
if let ExprKind::Struct(QPath::Resolved(_, path), ..) = e.kind {

0 commit comments

Comments
 (0)