Skip to content

Commit 0980622

Browse files
m-ou-secuviper
authored andcommitted
Don't allow flattened format_args in const.
(cherry picked from commit cc791eb)
1 parent 9d6fe3d commit 0980622

File tree

1 file changed

+8
-1
lines changed
  • library/core/src/fmt

1 file changed

+8
-1
lines changed

library/core/src/fmt/rt.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,15 @@ impl Argument<'_> {
205205
/// let f = format_args!("{}", "a");
206206
/// println!("{f}");
207207
/// ```
208+
///
209+
/// This function should _not_ be const, to make sure we don't accept
210+
/// format_args!() and panic!() with arguments in const, even when not evaluated:
211+
///
212+
/// ```compile_fail,E0015
213+
/// const _: () = if false { panic!("a {}", "a") };
214+
/// ```
208215
#[inline]
209-
pub const fn none() -> [Self; 0] {
216+
pub fn none() -> [Self; 0] {
210217
[]
211218
}
212219
}

0 commit comments

Comments
 (0)