diff options
| author | bors <bors@rust-lang.org> | 2019-09-24 10:58:41 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2019-09-24 10:58:41 +0000 |
| commit | 6ef275e6c3cb1384ec78128eceeb4963ff788dca (patch) | |
| tree | e2e776a76307c183bb2a762a2b1f630b71339b68 /src/libcore | |
| parent | 7fdea7a72abb9f5a58fdc19c0a298042291c53b2 (diff) | |
| parent | 7767e7fb165d527f1991175809a361f2d2313b80 (diff) | |
| download | rust-6ef275e6c3cb1384ec78128eceeb4963ff788dca.tar.gz rust-6ef275e6c3cb1384ec78128eceeb4963ff788dca.zip | |
Auto merge of #63770 - oli-obk:allow_internal_unstable, r=Centril
Stabilize `str::len`, `[T]::len` and `str::as_bytes` as const fn r? @Centril cc @RalfJung This also introduces a scheme for making certain feature gates legal in stabilized const fns
Diffstat (limited to 'src/libcore')
| -rw-r--r-- | src/libcore/lib.rs | 6 | ||||
| -rw-r--r-- | src/libcore/slice/mod.rs | 6 | ||||
| -rw-r--r-- | src/libcore/str/mod.rs | 8 |
3 files changed, 12 insertions, 8 deletions
diff --git a/src/libcore/lib.rs b/src/libcore/lib.rs index 5c681b3a5d8..8221df56a51 100644 --- a/src/libcore/lib.rs +++ b/src/libcore/lib.rs @@ -120,9 +120,9 @@ #![feature(rtm_target_feature)] #![feature(f16c_target_feature)] #![feature(hexagon_target_feature)] -#![feature(const_slice_len)] -#![feature(const_str_as_bytes)] -#![feature(const_str_len)] +#![cfg_attr(bootstrap, feature(const_slice_len))] +#![cfg_attr(bootstrap, feature(const_str_as_bytes))] +#![cfg_attr(bootstrap, feature(const_str_len))] #![feature(const_int_conversion)] #![feature(const_transmute)] #![feature(non_exhaustive)] 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 } 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> { |
