Skip to content

Commit

Permalink
Auto merge of #130538 - ultrabear:ultrabear_const_from_ref, r=working…
Browse files Browse the repository at this point in the history
…jubilee

Stabilize const `{slice,array}::from_mut`

This PR stabilizes the following APIs as const stable as of rust `1.83`:
```rs
// core::array
pub const fn from_mut<T>(s: &mut T) -> &mut [T; 1];

// core::slice
pub const fn from_mut<T>(s: &mut T) -> &mut [T];
```
This is made possible by `const_mut_refs` being stabilized (yay).

Tracking issue: #90206
  • Loading branch information
bors committed Oct 9, 2024
2 parents a1eceec + 461b49d commit 4ba32c6
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 6 deletions.
3 changes: 2 additions & 1 deletion library/core/src/array/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ pub const fn from_ref<T>(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 = "90206")]
#[rustc_const_stable(feature = "const_array_from_ref", since = "CURRENT_RUSTC_VERSION")]
#[cfg_attr(bootstrap, rustc_allow_const_fn_unstable(const_mut_refs))]
pub const fn from_mut<T>(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]>() }
Expand Down
2 changes: 0 additions & 2 deletions library/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@
#![feature(const_align_offset)]
#![feature(const_alloc_layout)]
#![feature(const_arguments_as_str)]
#![feature(const_array_from_ref)]
#![feature(const_array_into_iter_constructors)]
#![feature(const_bigint_helper_methods)]
#![feature(const_black_box)]
Expand Down Expand Up @@ -145,7 +144,6 @@
#![feature(const_replace)]
#![feature(const_size_of_val)]
#![feature(const_size_of_val_raw)]
#![feature(const_slice_from_ref)]
#![feature(const_strict_overflow_ops)]
#![feature(const_swap)]
#![feature(const_try)]
Expand Down
3 changes: 2 additions & 1 deletion library/core/src/slice/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,8 @@ pub const fn from_ref<T>(s: &T) -> &[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 = "90206")]
#[rustc_const_stable(feature = "const_slice_from_ref", since = "CURRENT_RUSTC_VERSION")]
#[cfg_attr(bootstrap, rustc_allow_const_fn_unstable(const_mut_refs))]
#[must_use]
pub const fn from_mut<T>(s: &mut T) -> &mut [T] {
array::from_mut(s)
Expand Down
2 changes: 0 additions & 2 deletions library/core/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#![feature(clone_to_uninit)]
#![feature(const_align_of_val_raw)]
#![feature(const_align_offset)]
#![feature(const_array_from_ref)]
#![feature(const_black_box)]
#![feature(const_hash)]
#![feature(const_heap)]
Expand All @@ -31,7 +30,6 @@
#![feature(const_pointer_is_aligned)]
#![feature(const_ptr_write)]
#![feature(const_result)]
#![feature(const_slice_from_ref)]
#![feature(const_three_way_compare)]
#![feature(const_trait_impl)]
#![feature(core_intrinsics)]
Expand Down

0 comments on commit 4ba32c6

Please sign in to comment.