@@ -797,7 +797,8 @@ impl<T> Option<T> {
797
797
#[ inline]
798
798
#[ must_use]
799
799
#[ stable( feature = "option_as_slice" , since = "1.75.0" ) ]
800
- pub fn as_slice ( & self ) -> & [ T ] {
800
+ #[ rustc_const_unstable( feature = "const_option_ext" , issue = "91930" ) ]
801
+ pub const fn as_slice ( & self ) -> & [ T ] {
801
802
// SAFETY: When the `Option` is `Some`, we're using the actual pointer
802
803
// to the payload, with a length of 1, so this is equivalent to
803
804
// `slice::from_ref`, and thus is safe.
@@ -811,7 +812,7 @@ impl<T> Option<T> {
811
812
unsafe {
812
813
slice:: from_raw_parts (
813
814
( self as * const Self ) . byte_add ( core:: mem:: offset_of!( Self , Some . 0 ) ) . cast ( ) ,
814
- usize :: from ( self . is_some ( ) ) ,
815
+ self . is_some ( ) as usize ,
815
816
)
816
817
}
817
818
}
@@ -851,7 +852,8 @@ impl<T> Option<T> {
851
852
#[ inline]
852
853
#[ must_use]
853
854
#[ stable( feature = "option_as_slice" , since = "1.75.0" ) ]
854
- pub fn as_mut_slice ( & mut self ) -> & mut [ T ] {
855
+ #[ rustc_const_unstable( feature = "const_option_ext" , issue = "91930" ) ]
856
+ pub const fn as_mut_slice ( & mut self ) -> & mut [ T ] {
855
857
// SAFETY: When the `Option` is `Some`, we're using the actual pointer
856
858
// to the payload, with a length of 1, so this is equivalent to
857
859
// `slice::from_mut`, and thus is safe.
@@ -867,7 +869,7 @@ impl<T> Option<T> {
867
869
unsafe {
868
870
slice:: from_raw_parts_mut (
869
871
( self as * mut Self ) . byte_add ( core:: mem:: offset_of!( Self , Some . 0 ) ) . cast ( ) ,
870
- usize :: from ( self . is_some ( ) ) ,
872
+ self . is_some ( ) as usize ,
871
873
)
872
874
}
873
875
}
0 commit comments