Skip to content

Commit

Permalink
Auto merge of #86655 - jonas-schievink:const-arguments-as-str, r=kennytm
Browse files Browse the repository at this point in the history
Make `fmt::Arguments::as_str` unstably const

Motivation: mostly to move "panic!() in const contexts" forward, making use of `as_str` was mentioned in #85194 (comment) and seems like the simplest way forward.
  • Loading branch information
bors committed Jun 27, 2021
2 parents 49ba936 + b3fbfe4 commit 9cdb2d3
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion library/core/src/fmt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -444,8 +444,9 @@ impl<'a> Arguments<'a> {
/// assert_eq!(format_args!("{}", 1).as_str(), None);
/// ```
#[stable(feature = "fmt_as_str", since = "1.52.0")]
#[rustc_const_unstable(feature = "const_arguments_as_str", issue = "none")]
#[inline]
pub fn as_str(&self) -> Option<&'static str> {
pub const fn as_str(&self) -> Option<&'static str> {
match (self.pieces, self.args) {
([], []) => Some(""),
([s], []) => Some(s),
Expand Down

0 comments on commit 9cdb2d3

Please sign in to comment.