From a288bf6afbf7f98fd357b971b23ef09a66aaa8c0 Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Fri, 22 Oct 2021 11:15:56 +0300 Subject: Mark {array,slice}::{from_ref,from_mut} as const fn --- library/core/src/array/mod.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'library/core/src/array') diff --git a/library/core/src/array/mod.rs b/library/core/src/array/mod.rs index 8d5c0510404..752e3fceb35 100644 --- a/library/core/src/array/mod.rs +++ b/library/core/src/array/mod.rs @@ -85,14 +85,16 @@ where /// Converts a reference to `T` into a reference to an array of length 1 (without copying). #[stable(feature = "array_from_ref", since = "1.53.0")] -pub fn from_ref(s: &T) -> &[T; 1] { +#[rustc_const_unstable(feature = "const_array_from_ref", issue = "none")] +pub const fn from_ref(s: &T) -> &[T; 1] { // SAFETY: Converting `&T` to `&[T; 1]` is sound. unsafe { &*(s as *const T).cast::<[T; 1]>() } } /// Converts a mutable reference to `T` into a mutable reference to an array of length 1 (without copying). #[stable(feature = "array_from_ref", since = "1.53.0")] -pub fn from_mut(s: &mut T) -> &mut [T; 1] { +#[rustc_const_unstable(feature = "const_array_from_ref", issue = "none")] +pub const fn from_mut(s: &mut T) -> &mut [T; 1] { // SAFETY: Converting `&mut T` to `&mut [T; 1]` is sound. unsafe { &mut *(s as *mut T).cast::<[T; 1]>() } } -- cgit 1.4.1-3-g733a5 From 27d69611347142cc5f103df0923b46d670e75739 Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Sat, 23 Oct 2021 20:59:15 +0300 Subject: Fill tracking issue for `const_slice_from_ref` and `const_array_from_ref` --- library/core/src/array/mod.rs | 4 ++-- library/core/src/slice/raw.rs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'library/core/src/array') diff --git a/library/core/src/array/mod.rs b/library/core/src/array/mod.rs index 752e3fceb35..5286ea60e3f 100644 --- a/library/core/src/array/mod.rs +++ b/library/core/src/array/mod.rs @@ -85,7 +85,7 @@ where /// Converts a reference to `T` into a reference to an array of length 1 (without copying). #[stable(feature = "array_from_ref", since = "1.53.0")] -#[rustc_const_unstable(feature = "const_array_from_ref", issue = "none")] +#[rustc_const_unstable(feature = "const_array_from_ref", issue = "90206")] pub const fn from_ref(s: &T) -> &[T; 1] { // SAFETY: Converting `&T` to `&[T; 1]` is sound. unsafe { &*(s as *const T).cast::<[T; 1]>() } @@ -93,7 +93,7 @@ pub const fn from_ref(s: &T) -> &[T; 1] { /// Converts a mutable reference to `T` into a mutable reference to an array of length 1 (without copying). #[stable(feature = "array_from_ref", since = "1.53.0")] -#[rustc_const_unstable(feature = "const_array_from_ref", issue = "none")] +#[rustc_const_unstable(feature = "const_array_from_ref", issue = "90206")] pub const fn from_mut(s: &mut T) -> &mut [T; 1] { // SAFETY: Converting `&mut T` to `&mut [T; 1]` is sound. unsafe { &mut *(s as *mut T).cast::<[T; 1]>() } diff --git a/library/core/src/slice/raw.rs b/library/core/src/slice/raw.rs index bcf3d9ba48e..ad38aaf9f83 100644 --- a/library/core/src/slice/raw.rs +++ b/library/core/src/slice/raw.rs @@ -138,14 +138,14 @@ pub unsafe fn from_raw_parts_mut<'a, T>(data: *mut T, len: usize) -> &'a mut [T] /// Converts a reference to T into a slice of length 1 (without copying). #[stable(feature = "from_ref", since = "1.28.0")] -#[rustc_const_unstable(feature = "const_slice_from_ref", issue = "none")] +#[rustc_const_unstable(feature = "const_slice_from_ref", issue = "90206")] pub const fn from_ref(s: &T) -> &[T] { array::from_ref(s) } /// Converts a reference to T into a slice of length 1 (without copying). #[stable(feature = "from_ref", since = "1.28.0")] -#[rustc_const_unstable(feature = "const_slice_from_ref", issue = "none")] +#[rustc_const_unstable(feature = "const_slice_from_ref", issue = "90206")] pub const fn from_mut(s: &mut T) -> &mut [T] { array::from_mut(s) } -- cgit 1.4.1-3-g733a5