about summary refs log tree commit diff
path: root/src/libcore/slice
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/slice
parent7fdea7a72abb9f5a58fdc19c0a298042291c53b2 (diff)
Stabilize `str::len`, `[T]::len`, `is_empty` and `str::as_bytes` as const fn
Diffstat (limited to 'src/libcore/slice')
-rw-r--r--src/libcore/slice/mod.rs6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/libcore/slice/mod.rs b/src/libcore/slice/mod.rs
index 931768564ca..0c2a4e08672 100644
--- a/src/libcore/slice/mod.rs
+++ b/src/libcore/slice/mod.rs
@@ -62,7 +62,9 @@ impl<T> [T] {
     /// ```
     #[stable(feature = "rust1", since = "1.0.0")]
     #[inline]
-    #[rustc_const_unstable(feature = "const_slice_len")]
+    #[cfg_attr(bootstrap, rustc_const_unstable(feature = "const_slice_len"))]
+    // SAFETY: const sound because we transmute out the length field as a usize (which it must be)
+    #[cfg_attr(not(bootstrap), allow_internal_unstable(const_fn_union))]
     pub const fn len(&self) -> usize {
         unsafe {
             crate::ptr::Repr { rust: self }.raw.len
@@ -79,7 +81,7 @@ impl<T> [T] {
     /// ```
     #[stable(feature = "rust1", since = "1.0.0")]
     #[inline]
-    #[rustc_const_unstable(feature = "const_slice_len")]
+    #[cfg_attr(bootstrap, rustc_const_unstable(feature = "const_slice_len"))]
     pub const fn is_empty(&self) -> bool {
         self.len() == 0
     }