Skip to content

Commit

Permalink
Rollup merge of rust-lang#116220 - llogiq:stabilize-option-as-slice, …
Browse files Browse the repository at this point in the history
…r=BurntSushi

stabilize `Option::as_`(`mut_`)`slice`

This is the stabilization to rust-lang#108545. Thanks to everyone who helped getting this into Rust proper.
  • Loading branch information
matthiaskrgr authored Oct 5, 2023
2 parents 44e37ea + 702da3b commit 50de0e6
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 13 deletions.
1 change: 0 additions & 1 deletion compiler/rustc_hir_typeck/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#![feature(box_patterns)]
#![feature(min_specialization)]
#![feature(control_flow_enum)]
#![feature(option_as_slice)]
#![recursion_limit = "256"]

#[macro_use]
Expand Down
14 changes: 2 additions & 12 deletions library/core/src/option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -743,8 +743,6 @@ impl<T> Option<T> {
/// # Examples
///
/// ```rust
/// #![feature(option_as_slice)]
///
/// assert_eq!(
/// [Some(1234).as_slice(), None.as_slice()],
/// [&[1234][..], &[][..]],
Expand All @@ -755,15 +753,13 @@ impl<T> Option<T> {
/// borrowing) [`[_]::first`](slice::first):
///
/// ```rust
/// #![feature(option_as_slice)]
///
/// for i in [Some(1234_u16), None] {
/// assert_eq!(i.as_ref(), i.as_slice().first());
/// }
/// ```
#[inline]
#[must_use]
#[unstable(feature = "option_as_slice", issue = "108545")]
#[stable(feature = "option_as_slice", since = "CURRENT_RUSTC_VERSION")]
pub fn as_slice(&self) -> &[T] {
// SAFETY: When the `Option` is `Some`, we're using the actual pointer
// to the payload, with a length of 1, so this is equivalent to
Expand Down Expand Up @@ -794,8 +790,6 @@ impl<T> Option<T> {
/// # Examples
///
/// ```rust
/// #![feature(option_as_slice)]
///
/// assert_eq!(
/// [Some(1234).as_mut_slice(), None.as_mut_slice()],
/// [&mut [1234][..], &mut [][..]],
Expand All @@ -806,8 +800,6 @@ impl<T> Option<T> {
/// our original `Option`:
///
/// ```rust
/// #![feature(option_as_slice)]
///
/// let mut x = Some(1234);
/// x.as_mut_slice()[0] += 1;
/// assert_eq!(x, Some(1235));
Expand All @@ -817,13 +809,11 @@ impl<T> Option<T> {
/// is [`[_]::first_mut`](slice::first_mut):
///
/// ```rust
/// #![feature(option_as_slice)]
///
/// assert_eq!(Some(123).as_mut_slice().first_mut(), Some(&mut 123))
/// ```
#[inline]
#[must_use]
#[unstable(feature = "option_as_slice", issue = "108545")]
#[stable(feature = "option_as_slice", since = "CURRENT_RUSTC_VERSION")]
pub fn as_mut_slice(&mut self) -> &mut [T] {
// SAFETY: When the `Option` is `Some`, we're using the actual pointer
// to the payload, with a length of 1, so this is equivalent to
Expand Down

0 comments on commit 50de0e6

Please sign in to comment.