about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2021-06-27 15:45:29 +0000
committerbors <bors@rust-lang.org>2021-06-27 15:45:29 +0000
commit9cdb2d3d59bad2843330535a41d0ebbb831fe57e (patch)
tree9575d2912aefdbb1a2c65e686073a1528c5e9d05
parent49ba9361d87f5d58d54fdd164ef2128cd50ed4b4 (diff)
parentb3fbfe474b40b5747161668d830e7589af71be92 (diff)
downloadrust-9cdb2d3d59bad2843330535a41d0ebbb831fe57e.tar.gz
rust-9cdb2d3d59bad2843330535a41d0ebbb831fe57e.zip
Auto merge of #86655 - jonas-schievink:const-arguments-as-str, r=kennytm
Make `fmt::Arguments::as_str` unstably const

Motivation: mostly to move "panic!() in const contexts" forward, making use of `as_str` was mentioned in https://github.com/rust-lang/rust/issues/85194#issuecomment-852345377 and seems like the simplest way forward.
-rw-r--r--library/core/src/fmt/mod.rs3
1 files changed, 2 insertions, 1 deletions
diff --git a/library/core/src/fmt/mod.rs b/library/core/src/fmt/mod.rs
index 409a84367a7..9ed49c1e302 100644
--- a/library/core/src/fmt/mod.rs
+++ b/library/core/src/fmt/mod.rs
@@ -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),