mirror of
https://github.com/rust-lang/rust.git
synced 2024-10-30 05:51:58 +00:00
Rollup merge of #131177 - workingjubilee:stabilize-const-mut-referees, r=tgross35
Stabilize 5 `const_mut_refs`-dependent API Since `const_mut_refs` and `const_refs_to_cell` have been stabilized, we now may create mutable references inside our library API. Thus we now stabilize the `const fn` version of these public library APIs which required such in their implementation: - const `NonNull::as_mut` https://github.com/rust-lang/rust/issues/91822#issuecomment-2338930442 - const `slice::{first,last}_mut`: https://github.com/rust-lang/rust/issues/83570#issuecomment-2334847112 - const `str::as_{mut_ptr,bytes_mut}`: https://github.com/rust-lang/rust/issues/130086#issuecomment-2336408562 - const `str::from_utf8_unchecked_mut`: https://github.com/rust-lang/rust/issues/91005#issuecomment-2359820672 - const `UnsafeCell::get_mut`: https://github.com/rust-lang/rust/issues/88836#issuecomment-2359817772
This commit is contained in:
commit
882d660036
@ -2175,7 +2175,8 @@ impl<T: ?Sized> UnsafeCell<T> {
|
||||
/// ```
|
||||
#[inline(always)]
|
||||
#[stable(feature = "unsafe_cell_get_mut", since = "1.50.0")]
|
||||
#[rustc_const_unstable(feature = "const_unsafecell_get_mut", issue = "88836")]
|
||||
#[cfg_attr(bootstrap, rustc_allow_const_fn_unstable(const_mut_refs))]
|
||||
#[rustc_const_stable(feature = "const_unsafecell_get_mut", since = "CURRENT_RUSTC_VERSION")]
|
||||
pub const fn get_mut(&mut self) -> &mut T {
|
||||
&mut self.value
|
||||
}
|
||||
|
@ -138,7 +138,6 @@
|
||||
#![feature(const_option_ext)]
|
||||
#![feature(const_pin)]
|
||||
#![feature(const_pointer_is_aligned)]
|
||||
#![feature(const_ptr_as_ref)]
|
||||
#![feature(const_ptr_is_null)]
|
||||
#![feature(const_ptr_sub_ptr)]
|
||||
#![feature(const_ptr_write)]
|
||||
@ -149,8 +148,6 @@
|
||||
#![feature(const_slice_from_raw_parts_mut)]
|
||||
#![feature(const_slice_from_ref)]
|
||||
#![feature(const_slice_split_at_mut)]
|
||||
#![feature(const_str_as_mut)]
|
||||
#![feature(const_str_from_utf8_unchecked_mut)]
|
||||
#![feature(const_strict_overflow_ops)]
|
||||
#![feature(const_swap)]
|
||||
#![feature(const_try)]
|
||||
@ -159,7 +156,6 @@
|
||||
#![feature(const_typed_swap)]
|
||||
#![feature(const_ub_checks)]
|
||||
#![feature(const_unicode_case_lookup)]
|
||||
#![feature(const_unsafecell_get_mut)]
|
||||
#![feature(coverage_attribute)]
|
||||
#![feature(do_not_recommend)]
|
||||
#![feature(duration_consts_float)]
|
||||
|
@ -394,7 +394,8 @@ impl<T: ?Sized> NonNull<T> {
|
||||
///
|
||||
/// [the module documentation]: crate::ptr#safety
|
||||
#[stable(feature = "nonnull", since = "1.25.0")]
|
||||
#[rustc_const_unstable(feature = "const_ptr_as_ref", issue = "91822")]
|
||||
#[cfg_attr(bootstrap, rustc_allow_const_fn_unstable(const_mut_refs))]
|
||||
#[rustc_const_stable(feature = "const_ptr_as_ref", since = "CURRENT_RUSTC_VERSION")]
|
||||
#[must_use]
|
||||
#[inline(always)]
|
||||
pub const unsafe fn as_mut<'a>(&mut self) -> &'a mut T {
|
||||
|
@ -171,7 +171,8 @@ impl<T> [T] {
|
||||
/// assert_eq!(None, y.first_mut());
|
||||
/// ```
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_slice_first_last", issue = "83570")]
|
||||
#[cfg_attr(bootstrap, rustc_allow_const_fn_unstable(const_mut_refs))]
|
||||
#[rustc_const_stable(feature = "const_slice_first_last", since = "CURRENT_RUSTC_VERSION")]
|
||||
#[inline]
|
||||
#[must_use]
|
||||
pub const fn first_mut(&mut self) -> Option<&mut T> {
|
||||
@ -213,7 +214,8 @@ impl<T> [T] {
|
||||
/// assert_eq!(x, &[3, 4, 5]);
|
||||
/// ```
|
||||
#[stable(feature = "slice_splits", since = "1.5.0")]
|
||||
#[rustc_const_unstable(feature = "const_slice_first_last", issue = "83570")]
|
||||
#[cfg_attr(bootstrap, rustc_allow_const_fn_unstable(const_mut_refs))]
|
||||
#[rustc_const_stable(feature = "const_slice_first_last", since = "CURRENT_RUSTC_VERSION")]
|
||||
#[inline]
|
||||
#[must_use]
|
||||
pub const fn split_first_mut(&mut self) -> Option<(&mut T, &mut [T])> {
|
||||
@ -255,7 +257,8 @@ impl<T> [T] {
|
||||
/// assert_eq!(x, &[4, 5, 3]);
|
||||
/// ```
|
||||
#[stable(feature = "slice_splits", since = "1.5.0")]
|
||||
#[rustc_const_unstable(feature = "const_slice_first_last", issue = "83570")]
|
||||
#[cfg_attr(bootstrap, rustc_allow_const_fn_unstable(const_mut_refs))]
|
||||
#[rustc_const_stable(feature = "const_slice_first_last", since = "CURRENT_RUSTC_VERSION")]
|
||||
#[inline]
|
||||
#[must_use]
|
||||
pub const fn split_last_mut(&mut self) -> Option<(&mut T, &mut [T])> {
|
||||
@ -297,7 +300,8 @@ impl<T> [T] {
|
||||
/// assert_eq!(None, y.last_mut());
|
||||
/// ```
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[rustc_const_unstable(feature = "const_slice_first_last", issue = "83570")]
|
||||
#[cfg_attr(bootstrap, rustc_allow_const_fn_unstable(const_mut_refs))]
|
||||
#[rustc_const_stable(feature = "const_slice_first_last", since = "CURRENT_RUSTC_VERSION")]
|
||||
#[inline]
|
||||
#[must_use]
|
||||
pub const fn last_mut(&mut self) -> Option<&mut T> {
|
||||
|
@ -195,7 +195,11 @@ pub const unsafe fn from_utf8_unchecked(v: &[u8]) -> &str {
|
||||
#[inline]
|
||||
#[must_use]
|
||||
#[stable(feature = "str_mut_extras", since = "1.20.0")]
|
||||
#[rustc_const_unstable(feature = "const_str_from_utf8_unchecked_mut", issue = "91005")]
|
||||
#[cfg_attr(bootstrap, rustc_allow_const_fn_unstable(const_mut_refs))]
|
||||
#[rustc_const_stable(
|
||||
feature = "const_str_from_utf8_unchecked_mut",
|
||||
since = "CURRENT_RUSTC_VERSION"
|
||||
)]
|
||||
#[rustc_diagnostic_item = "str_from_utf8_unchecked_mut"]
|
||||
pub const unsafe fn from_utf8_unchecked_mut(v: &mut [u8]) -> &mut str {
|
||||
// SAFETY: the caller must guarantee that the bytes `v`
|
||||
|
@ -339,7 +339,8 @@ impl str {
|
||||
/// assert_eq!("🍔∈🌏", s);
|
||||
/// ```
|
||||
#[stable(feature = "str_mut_extras", since = "1.20.0")]
|
||||
#[rustc_const_unstable(feature = "const_str_as_mut", issue = "130086")]
|
||||
#[cfg_attr(bootstrap, rustc_allow_const_fn_unstable(const_mut_refs))]
|
||||
#[rustc_const_stable(feature = "const_str_as_mut", since = "CURRENT_RUSTC_VERSION")]
|
||||
#[must_use]
|
||||
#[inline(always)]
|
||||
pub const unsafe fn as_bytes_mut(&mut self) -> &mut [u8] {
|
||||
@ -385,7 +386,8 @@ impl str {
|
||||
/// It is your responsibility to make sure that the string slice only gets
|
||||
/// modified in a way that it remains valid UTF-8.
|
||||
#[stable(feature = "str_as_mut_ptr", since = "1.36.0")]
|
||||
#[rustc_const_unstable(feature = "const_str_as_mut", issue = "130086")]
|
||||
#[cfg_attr(bootstrap, rustc_allow_const_fn_unstable(const_mut_refs))]
|
||||
#[rustc_const_stable(feature = "const_str_as_mut", since = "CURRENT_RUSTC_VERSION")]
|
||||
#[rustc_never_returns_null_ptr]
|
||||
#[must_use]
|
||||
#[inline(always)]
|
||||
|
@ -29,7 +29,6 @@
|
||||
#![feature(const_option_ext)]
|
||||
#![feature(const_pin)]
|
||||
#![feature(const_pointer_is_aligned)]
|
||||
#![feature(const_ptr_as_ref)]
|
||||
#![feature(const_ptr_write)]
|
||||
#![feature(const_result)]
|
||||
#![feature(const_slice_from_ref)]
|
||||
|
Loading…
Reference in New Issue
Block a user