about summary refs log tree commit diff
path: root/library/core/src
diff options
context:
space:
mode:
authorMara Bos <m-ou.se@m-ou.se>2023-04-24 17:31:32 +0200
committerMara Bos <m-ou.se@m-ou.se>2023-05-09 16:08:40 +0200
commitd5843ddaf1f3291e30b60af44b58dccbcd9b6090 (patch)
tree36b8999c98f1cd3135d43971bbf80a4b07482722 /library/core/src
parentecd3dbab4ed82abfa05e22069261e565239449cf (diff)
downloadrust-d5843ddaf1f3291e30b60af44b58dccbcd9b6090.tar.gz
rust-d5843ddaf1f3291e30b60af44b58dccbcd9b6090.zip
Limit lifetime of format_args!() with inlined args.
Diffstat (limited to 'library/core/src')
-rw-r--r--library/core/src/fmt/rt.rs15
1 files changed, 15 insertions, 0 deletions
diff --git a/library/core/src/fmt/rt.rs b/library/core/src/fmt/rt.rs
index 0596f6c30ce..d37888c27bd 100644
--- a/library/core/src/fmt/rt.rs
+++ b/library/core/src/fmt/rt.rs
@@ -152,6 +152,21 @@ impl<'a> Argument<'a> {
             None
         }
     }
+
+    /// Used by `format_args` when all arguments are gone after inlining,
+    /// when using `&[]` would incorrectly allow for a bigger lifetime.
+    ///
+    /// This fails without format argument inlining, and that shouldn't be different
+    /// when the argument is inlined:
+    ///
+    /// ```compile_fail,E0716
+    /// let f = format_args!("{}", "a");
+    /// println!("{f}");
+    /// ```
+    #[inline(always)]
+    pub fn none() -> [Self; 0] {
+        []
+    }
 }
 
 /// This struct represents the unsafety of constructing an `Arguments`.