mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-29 18:23:49 +00:00
Rollup merge of #130538 - ultrabear:ultrabear_const_from_ref, r=workingjubilee
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
This commit is contained in:
commit
9237937cf0
@ -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).
|
/// 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")]
|
#[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] {
|
pub const fn from_mut<T>(s: &mut T) -> &mut [T; 1] {
|
||||||
// SAFETY: Converting `&mut T` to `&mut [T; 1]` is sound.
|
// SAFETY: Converting `&mut T` to `&mut [T; 1]` is sound.
|
||||||
unsafe { &mut *(s as *mut T).cast::<[T; 1]>() }
|
unsafe { &mut *(s as *mut T).cast::<[T; 1]>() }
|
||||||
|
@ -114,7 +114,6 @@
|
|||||||
#![feature(const_align_offset)]
|
#![feature(const_align_offset)]
|
||||||
#![feature(const_alloc_layout)]
|
#![feature(const_alloc_layout)]
|
||||||
#![feature(const_arguments_as_str)]
|
#![feature(const_arguments_as_str)]
|
||||||
#![feature(const_array_from_ref)]
|
|
||||||
#![feature(const_array_into_iter_constructors)]
|
#![feature(const_array_into_iter_constructors)]
|
||||||
#![feature(const_bigint_helper_methods)]
|
#![feature(const_bigint_helper_methods)]
|
||||||
#![feature(const_black_box)]
|
#![feature(const_black_box)]
|
||||||
@ -145,7 +144,6 @@
|
|||||||
#![feature(const_replace)]
|
#![feature(const_replace)]
|
||||||
#![feature(const_size_of_val)]
|
#![feature(const_size_of_val)]
|
||||||
#![feature(const_size_of_val_raw)]
|
#![feature(const_size_of_val_raw)]
|
||||||
#![feature(const_slice_from_ref)]
|
|
||||||
#![feature(const_strict_overflow_ops)]
|
#![feature(const_strict_overflow_ops)]
|
||||||
#![feature(const_swap)]
|
#![feature(const_swap)]
|
||||||
#![feature(const_try)]
|
#![feature(const_try)]
|
||||||
|
@ -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).
|
/// Converts a reference to T into a slice of length 1 (without copying).
|
||||||
#[stable(feature = "from_ref", since = "1.28.0")]
|
#[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]
|
#[must_use]
|
||||||
pub const fn from_mut<T>(s: &mut T) -> &mut [T] {
|
pub const fn from_mut<T>(s: &mut T) -> &mut [T] {
|
||||||
array::from_mut(s)
|
array::from_mut(s)
|
||||||
|
@ -16,7 +16,6 @@
|
|||||||
#![feature(clone_to_uninit)]
|
#![feature(clone_to_uninit)]
|
||||||
#![feature(const_align_of_val_raw)]
|
#![feature(const_align_of_val_raw)]
|
||||||
#![feature(const_align_offset)]
|
#![feature(const_align_offset)]
|
||||||
#![feature(const_array_from_ref)]
|
|
||||||
#![feature(const_black_box)]
|
#![feature(const_black_box)]
|
||||||
#![feature(const_hash)]
|
#![feature(const_hash)]
|
||||||
#![feature(const_heap)]
|
#![feature(const_heap)]
|
||||||
@ -31,7 +30,6 @@
|
|||||||
#![feature(const_pointer_is_aligned)]
|
#![feature(const_pointer_is_aligned)]
|
||||||
#![feature(const_ptr_write)]
|
#![feature(const_ptr_write)]
|
||||||
#![feature(const_result)]
|
#![feature(const_result)]
|
||||||
#![feature(const_slice_from_ref)]
|
|
||||||
#![feature(const_three_way_compare)]
|
#![feature(const_three_way_compare)]
|
||||||
#![feature(const_trait_impl)]
|
#![feature(const_trait_impl)]
|
||||||
#![feature(core_intrinsics)]
|
#![feature(core_intrinsics)]
|
||||||
|
Loading…
Reference in New Issue
Block a user