Skip to content

Commit 4873ebe

Browse files
committed
Use ZST for fmt unsafety
This allows the format_args! macro to keep the pre-expansion code out of the unsafe block without doing gymnastics with nested `match` expressions. This reduces codegen.
1 parent d37f109 commit 4873ebe

File tree

1 file changed

+15
-20
lines changed

1 file changed

+15
-20
lines changed

clippy_utils/src/higher.rs

+15-20
Original file line numberDiff line numberDiff line change
@@ -524,28 +524,12 @@ impl FormatArgsExpn<'tcx> {
524524
if let ExpnKind::Macro(_, name) = expr.span.ctxt().outer_expn_data().kind;
525525
let name = name.as_str();
526526
if name.ends_with("format_args") || name.ends_with("format_args_nl");
527-
528-
if let ExprKind::Match(inner_match, [arm], _) = expr.kind;
529-
530-
// `match match`, if you will
531-
if let ExprKind::Match(args, [inner_arm], _) = inner_match.kind;
532-
if let ExprKind::Tup(value_args) = args.kind;
533-
if let Some(value_args) = value_args
534-
.iter()
535-
.map(|e| match e.kind {
536-
ExprKind::AddrOf(_, _, e) => Some(e),
537-
_ => None,
538-
})
539-
.collect();
540-
if let ExprKind::Array(args) = inner_arm.body.kind;
541-
542-
if let ExprKind::Block(Block { stmts: [], expr: Some(expr), .. }, _) = arm.body.kind;
543-
if let ExprKind::Call(_, call_args) = expr.kind;
544-
if let Some((strs_ref, fmt_expr)) = match call_args {
527+
if let ExprKind::Call(_, args) = expr.kind;
528+
if let Some((strs_ref, args, fmt_expr)) = match args {
545529
// Arguments::new_v1
546-
[strs_ref, _] => Some((strs_ref, None)),
530+
[strs_ref, args] => Some((strs_ref, args, None)),
547531
// Arguments::new_v1_formatted
548-
[strs_ref, _, fmt_expr] => Some((strs_ref, Some(fmt_expr))),
532+
[strs_ref, args, fmt_expr, _unsafe_arg] => Some((strs_ref, args, Some(fmt_expr))),
549533
_ => None,
550534
};
551535
if let ExprKind::AddrOf(BorrowKind::Ref, _, strs_arr) = strs_ref.kind;
@@ -561,6 +545,17 @@ impl FormatArgsExpn<'tcx> {
561545
None
562546
})
563547
.collect();
548+
if let ExprKind::AddrOf(BorrowKind::Ref, _, args) = args.kind;
549+
if let ExprKind::Match(args, [arm], _) = args.kind;
550+
if let ExprKind::Tup(value_args) = args.kind;
551+
if let Some(value_args) = value_args
552+
.iter()
553+
.map(|e| match e.kind {
554+
ExprKind::AddrOf(_, _, e) => Some(e),
555+
_ => None,
556+
})
557+
.collect();
558+
if let ExprKind::Array(args) = arm.body.kind;
564559
then {
565560
Some(FormatArgsExpn {
566561
format_string_span: strs_ref.span,

0 commit comments

Comments
 (0)