about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2021-09-23 02:10:26 +0000
committerbors <bors@rust-lang.org>2021-09-23 02:10:26 +0000
commit67365d64bcdfeae1334bf2ff49587c27d1c973f0 (patch)
treee675fccc48356eac3a83e78ae3894491a6c0ded5 /src
parent30278d3cf92b581550933546370443a5d5700002 (diff)
parent2efa9d796981163031a7478734fee561dc3a6da0 (diff)
downloadrust-67365d64bcdfeae1334bf2ff49587c27d1c973f0.tar.gz
rust-67365d64bcdfeae1334bf2ff49587c27d1c973f0.zip
Auto merge of #89139 - camsteffen:write-perf, r=Mark-Simulacrum
Use ZST for fmt unsafety

as suggested here - https://github.com/rust-lang/rust/pull/83302#issuecomment-923529151.
Diffstat (limited to 'src')
-rw-r--r--src/test/pretty/dollar-crate.pp10
-rw-r--r--src/test/pretty/issue-4264.pp56
-rw-r--r--src/test/run-make-fulldeps/coverage-reports/expected_show_coverage.issue-84561.txt6
-rw-r--r--src/test/ui/attributes/key-value-expansion.stderr16
-rw-r--r--src/tools/clippy/clippy_utils/src/higher.rs35
5 files changed, 51 insertions, 72 deletions
diff --git a/src/test/pretty/dollar-crate.pp b/src/test/pretty/dollar-crate.pp
index 4eccba06b13..f4be3c1c63a 100644
--- a/src/test/pretty/dollar-crate.pp
+++ b/src/test/pretty/dollar-crate.pp
@@ -10,11 +10,9 @@ extern crate std;
 
 fn main() {
     {
-        ::std::io::_print(match match () { () => [], } {
-                              ref args => unsafe {
-                                  ::core::fmt::Arguments::new_v1(&["rust\n"],
-                                                                 args)
-                              }
-                          });
+        ::std::io::_print(::core::fmt::Arguments::new_v1(&["rust\n"],
+                                                         &match () {
+                                                              () => [],
+                                                          }));
     };
 }
diff --git a/src/test/pretty/issue-4264.pp b/src/test/pretty/issue-4264.pp
index a21ea520121..199aee05622 100644
--- a/src/test/pretty/issue-4264.pp
+++ b/src/test/pretty/issue-4264.pp
@@ -32,39 +32,29 @@ pub fn bar() ({
                   ({
                        let res =
                            ((::alloc::fmt::format as
-                                for<'r> fn(Arguments<'r>) -> String {format})((match (match (()
-                                                                                                as
-                                                                                                ())
-                                                                                          {
-                                                                                          ()
-                                                                                          =>
-                                                                                          ([]
-                                                                                              as
-                                                                                              [ArgumentV1; 0]),
-                                                                                      }
-                                                                                         as
-                                                                                         [ArgumentV1; 0])
-                                                                                   {
-                                                                                   ref args
-                                                                                   =>
-                                                                                   unsafe
-                                                                                   {
-                                                                                       ((::core::fmt::Arguments::new_v1
-                                                                                            as
-                                                                                            unsafe fn(&[&'static str], &[ArgumentV1]) -> Arguments {Arguments::new_v1})((&([("test"
-                                                                                                                                                                                as
-                                                                                                                                                                                &str)]
-                                                                                                                                                                              as
-                                                                                                                                                                              [&str; 1])
-                                                                                                                                                                            as
-                                                                                                                                                                            &[&str; 1]),
-                                                                                                                                                                        (args
-                                                                                                                                                                            as
-                                                                                                                                                                            &[ArgumentV1; 0]))
-                                                                                           as
-                                                                                           Arguments)
-                                                                                   }
-                                                                               }
+                                for<'r> fn(Arguments<'r>) -> String {format})(((::core::fmt::Arguments::new_v1
+                                                                                   as
+                                                                                   fn(&[&'static str], &[ArgumentV1]) -> Arguments {Arguments::new_v1})((&([("test"
+                                                                                                                                                                as
+                                                                                                                                                                &str)]
+                                                                                                                                                              as
+                                                                                                                                                              [&str; 1])
+                                                                                                                                                            as
+                                                                                                                                                            &[&str; 1]),
+                                                                                                                                                        (&(match (()
+                                                                                                                                                                     as
+                                                                                                                                                                     ())
+                                                                                                                                                               {
+                                                                                                                                                               ()
+                                                                                                                                                               =>
+                                                                                                                                                               ([]
+                                                                                                                                                                   as
+                                                                                                                                                                   [ArgumentV1; 0]),
+                                                                                                                                                           }
+                                                                                                                                                              as
+                                                                                                                                                              [ArgumentV1; 0])
+                                                                                                                                                            as
+                                                                                                                                                            &[ArgumentV1; 0]))
                                                                                   as
                                                                                   Arguments))
                                as String);
diff --git a/src/test/run-make-fulldeps/coverage-reports/expected_show_coverage.issue-84561.txt b/src/test/run-make-fulldeps/coverage-reports/expected_show_coverage.issue-84561.txt
index b35f3f54de9..f24f7c69404 100644
--- a/src/test/run-make-fulldeps/coverage-reports/expected_show_coverage.issue-84561.txt
+++ b/src/test/run-make-fulldeps/coverage-reports/expected_show_coverage.issue-84561.txt
@@ -31,15 +31,15 @@
    24|      1|    println!("{:?}", Foo(1));
    25|      1|
    26|      1|    assert_ne!(Foo(0), Foo(5), "{}", if is_true { "true message" } else { "false message" });
-                                             ^0       ^0        ^0                      ^0
+                                             ^0                 ^0                      ^0
    27|      1|    assert_ne!(
    28|       |        Foo(0)
    29|       |        ,
    30|       |        Foo(5)
    31|       |        ,
    32|      0|        "{}"
-   33|       |        ,
-   34|       |        if
+   33|      0|        ,
+   34|      0|        if
    35|      0|        is_true
    36|       |        {
    37|      0|            "true message"
diff --git a/src/test/ui/attributes/key-value-expansion.stderr b/src/test/ui/attributes/key-value-expansion.stderr
index 03ca515265c..31e93ef54f2 100644
--- a/src/test/ui/attributes/key-value-expansion.stderr
+++ b/src/test/ui/attributes/key-value-expansion.stderr
@@ -17,16 +17,12 @@ LL | bug!();
 
 error: unexpected token: `{
     let res =
-        ::alloc::fmt::format(match match (&"u8",) {
-                                       (arg0,) =>
-                                       [::core::fmt::ArgumentV1::new(arg0,
-                                                                     ::core::fmt::Display::fmt)],
-                                   } {
-                                 ref args => unsafe {
-                                     ::core::fmt::Arguments::new_v1(&[""],
-                                                                    args)
-                                 }
-                             });
+        ::alloc::fmt::format(::core::fmt::Arguments::new_v1(&[""],
+                                                            &match (&"u8",) {
+                                                                 (arg0,) =>
+                                                                 [::core::fmt::ArgumentV1::new(arg0,
+                                                                                               ::core::fmt::Display::fmt)],
+                                                             }));
     res
 }.as_str()`
   --> $DIR/key-value-expansion.rs:48:23
diff --git a/src/tools/clippy/clippy_utils/src/higher.rs b/src/tools/clippy/clippy_utils/src/higher.rs
index 94b3cd371bd..e6c06224999 100644
--- a/src/tools/clippy/clippy_utils/src/higher.rs
+++ b/src/tools/clippy/clippy_utils/src/higher.rs
@@ -523,28 +523,12 @@ impl FormatArgsExpn<'tcx> {
             if let ExpnKind::Macro(_, name) = expr.span.ctxt().outer_expn_data().kind;
             let name = name.as_str();
             if name.ends_with("format_args") || name.ends_with("format_args_nl");
-
-            if let ExprKind::Match(inner_match, [arm], _) = expr.kind;
-
-            // `match match`, if you will
-            if let ExprKind::Match(args, [inner_arm], _) = inner_match.kind;
-            if let ExprKind::Tup(value_args) = args.kind;
-            if let Some(value_args) = value_args
-                .iter()
-                .map(|e| match e.kind {
-                    ExprKind::AddrOf(_, _, e) => Some(e),
-                    _ => None,
-                })
-                .collect();
-            if let ExprKind::Array(args) = inner_arm.body.kind;
-
-            if let ExprKind::Block(Block { stmts: [], expr: Some(expr), .. }, _) = arm.body.kind;
-            if let ExprKind::Call(_, call_args) = expr.kind;
-            if let Some((strs_ref, fmt_expr)) = match call_args {
+            if let ExprKind::Call(_, args) = expr.kind;
+            if let Some((strs_ref, args, fmt_expr)) = match args {
                 // Arguments::new_v1
-                [strs_ref, _] => Some((strs_ref, None)),
+                [strs_ref, args] => Some((strs_ref, args, None)),
                 // Arguments::new_v1_formatted
-                [strs_ref, _, fmt_expr] => Some((strs_ref, Some(fmt_expr))),
+                [strs_ref, args, fmt_expr, _unsafe_arg] => Some((strs_ref, args, Some(fmt_expr))),
                 _ => None,
             };
             if let ExprKind::AddrOf(BorrowKind::Ref, _, strs_arr) = strs_ref.kind;
@@ -560,6 +544,17 @@ impl FormatArgsExpn<'tcx> {
                     None
                 })
                 .collect();
+            if let ExprKind::AddrOf(BorrowKind::Ref, _, args) = args.kind;
+            if let ExprKind::Match(args, [arm], _) = args.kind;
+            if let ExprKind::Tup(value_args) = args.kind;
+            if let Some(value_args) = value_args
+                .iter()
+                .map(|e| match e.kind {
+                    ExprKind::AddrOf(_, _, e) => Some(e),
+                    _ => None,
+                })
+                .collect();
+            if let ExprKind::Array(args) = arm.body.kind;
             then {
                 Some(FormatArgsExpn {
                     format_string_span: strs_ref.span,