diff options
| author | Mara Bos <m-ou.se@m-ou.se> | 2025-04-10 11:49:08 +0200 |
|---|---|---|
| committer | Josh Stone <cuviper@gmail.com> | 2025-05-02 09:29:22 -0700 |
| commit | 09806220337d559ebbb41b4fdfcc452365d328e7 (patch) | |
| tree | 4a6534eba321b04e3a019b773d041ddbcf404306 | |
| parent | 9d6fe3d1b2e24fad0574ef47915df47c72ba2ee3 (diff) | |
| download | rust-09806220337d559ebbb41b4fdfcc452365d328e7.tar.gz rust-09806220337d559ebbb41b4fdfcc452365d328e7.zip | |
Don't allow flattened format_args in const.
(cherry picked from commit cc791ebe60f936355ffa62a53789cc69bcfde7e6)
| -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 d27f7e6e0d8..eab48466599 100644 --- a/library/core/src/fmt/rt.rs +++ b/library/core/src/fmt/rt.rs @@ -205,8 +205,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] { [] } } |
