diff options
| author | Mara Bos <m-ou.se@m-ou.se> | 2025-04-10 11:49:08 +0200 |
|---|---|---|
| committer | Mara Bos <m-ou.se@m-ou.se> | 2025-04-10 11:49:08 +0200 |
| commit | cc791ebe60f936355ffa62a53789cc69bcfde7e6 (patch) | |
| tree | 3c4c045789f01ae61da9efa63b2331b71f2a82ea | |
| parent | 9d28fe39763974a96d61232e96ac856735e4cdd6 (diff) | |
| download | rust-cc791ebe60f936355ffa62a53789cc69bcfde7e6.tar.gz rust-cc791ebe60f936355ffa62a53789cc69bcfde7e6.zip | |
Don't allow flattened format_args in const.
| -rw-r--r-- | library/core/src/fmt/rt.rs | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/library/core/src/fmt/rt.rs b/library/core/src/fmt/rt.rs index 0459674303d..754dda9f4ff 100644 --- a/library/core/src/fmt/rt.rs +++ b/library/core/src/fmt/rt.rs @@ -174,8 +174,15 @@ impl Argument<'_> { /// let f = format_args!("{}", "a"); /// println!("{f}"); /// ``` + /// + /// This function should _not_ be const, to make sure we don't accept + /// format_args!() and panic!() with arguments in const, even when not evaluated: + /// + /// ```compile_fail,E0015 + /// const _: () = if false { panic!("a {}", "a") }; + /// ``` #[inline] - pub const fn none() -> [Self; 0] { + pub fn none() -> [Self; 0] { [] } } |
