Skip to content

Commit 6619027

Browse files
committed
Auto merge of #139624 - m-ou-se:unconst-format-args, r=<try>
Don't allow flattened format_args in const. Fixes #139136 and #139621 by breaking the 'flattened format_args' cases. This is a breaking change. Let's try a crater run.
2 parents 9d28fe3 + cc791eb commit 6619027

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

+8-1
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,15 @@ impl Argument<'_> {
174174
/// let f = format_args!("{}", "a");
175175
/// println!("{f}");
176176
/// ```
177+
///
178+
/// This function should _not_ be const, to make sure we don't accept
179+
/// format_args!() and panic!() with arguments in const, even when not evaluated:
180+
///
181+
/// ```compile_fail,E0015
182+
/// const _: () = if false { panic!("a {}", "a") };
183+
/// ```
177184
#[inline]
178-
pub const fn none() -> [Self; 0] {
185+
pub fn none() -> [Self; 0] {
179186
[]
180187
}
181188
}

0 commit comments

Comments
 (0)