about summary refs log tree commit diff
path: root/src/libcore/str
diff options
context:
space:
mode:
authorOliver Scherer <github35764891676564198441@oli-obk.de>2019-08-21 02:23:46 +0200
committerOliver Scherer <github35764891676564198441@oli-obk.de>2019-09-24 12:56:44 +0200
commit7767e7fb165d527f1991175809a361f2d2313b80 (patch)
treee2e776a76307c183bb2a762a2b1f630b71339b68 /src/libcore/str
parent7fdea7a72abb9f5a58fdc19c0a298042291c53b2 (diff)
downloadrust-7767e7fb165d527f1991175809a361f2d2313b80.tar.gz
rust-7767e7fb165d527f1991175809a361f2d2313b80.zip
Stabilize `str::len`, `[T]::len`, `is_empty` and `str::as_bytes` as const fn
Diffstat (limited to 'src/libcore/str')
-rw-r--r--src/libcore/str/mod.rs8
1 files changed, 5 insertions, 3 deletions
diff --git a/src/libcore/str/mod.rs b/src/libcore/str/mod.rs
index 5e5b5593fd8..a6ec757faf1 100644
--- a/src/libcore/str/mod.rs
+++ b/src/libcore/str/mod.rs
@@ -2090,7 +2090,7 @@ impl str {
     /// ```
     #[stable(feature = "rust1", since = "1.0.0")]
     #[inline]
-    #[rustc_const_unstable(feature = "const_str_len")]
+    #[cfg_attr(bootstrap, rustc_const_unstable(feature = "const_str_len"))]
     pub const fn len(&self) -> usize {
         self.as_bytes().len()
     }
@@ -2110,7 +2110,7 @@ impl str {
     /// ```
     #[inline]
     #[stable(feature = "rust1", since = "1.0.0")]
-    #[rustc_const_unstable(feature = "const_str_len")]
+    #[cfg_attr(bootstrap, rustc_const_unstable(feature = "const_str_len"))]
     pub const fn is_empty(&self) -> bool {
         self.len() == 0
     }
@@ -2168,7 +2168,9 @@ impl str {
     /// ```
     #[stable(feature = "rust1", since = "1.0.0")]
     #[inline(always)]
-    #[rustc_const_unstable(feature="const_str_as_bytes")]
+    #[cfg_attr(bootstrap, rustc_const_unstable(feature = "const_str_as_bytes"))]
+    // SAFETY: const sound because we transmute two types with the same layout
+    #[cfg_attr(not(bootstrap), allow_internal_unstable(const_fn_union))]
     pub const fn as_bytes(&self) -> &[u8] {
         #[repr(C)]
         union Slices<'a> {