File tree Expand file tree Collapse file tree 5 files changed +14
-10
lines changed Expand file tree Collapse file tree 5 files changed +14
-10
lines changed Original file line number Diff line number Diff line change @@ -2487,12 +2487,6 @@ extern "rust-intrinsic" {
2487
2487
where
2488
2488
G : FnOnce < ARG , Output = RET > ,
2489
2489
F : FnOnce < ARG , Output = RET > ;
2490
-
2491
- /// This method creates a pointer to any `Some` value. If the argument is
2492
- /// `None`, an invalid within-bounds pointer (that is still acceptable for
2493
- /// constructing an empty slice) is returned.
2494
- #[ rustc_nounwind]
2495
- pub fn option_payload_ptr < T > ( arg : * const Option < T > ) -> * const T ;
2496
2490
}
2497
2491
2498
2492
// Some functions are defined here because they accidentally got made
Original file line number Diff line number Diff line change 97
97
// SAFETY: Loop conditions ensure the index is in bounds.
98
98
99
99
unsafe {
100
- let opt_payload_at = core:: intrinsics:: option_payload_ptr ( & val) ;
100
+ let opt_payload_at =
101
+ ( & val as * const Option < B > ) . byte_add ( core:: mem:: offset_of!( Option <B >, Some . 0 ) ) ;
101
102
let dst = guard. array . as_mut_ptr ( ) . add ( idx) ;
102
103
crate :: ptr:: copy_nonoverlapping ( opt_payload_at. cast ( ) , dst, 1 ) ;
103
104
crate :: mem:: forget ( val) ;
Original file line number Diff line number Diff line change 178
178
#![ feature( is_ascii_octdigit) ]
179
179
#![ feature( isqrt) ]
180
180
#![ feature( maybe_uninit_uninit_array) ]
181
+ #![ feature( offset_of) ]
182
+ #![ feature( offset_of_enum) ]
181
183
#![ feature( ptr_alignment_type) ]
182
184
#![ feature( ptr_metadata) ]
183
185
#![ feature( set_ptr_value) ]
Original file line number Diff line number Diff line change @@ -779,7 +779,7 @@ impl<T> Option<T> {
779
779
// `None` case it's just padding).
780
780
unsafe {
781
781
slice:: from_raw_parts (
782
- crate :: intrinsics :: option_payload_ptr ( crate :: ptr :: from_ref ( self ) ) ,
782
+ ( self as * const Self ) . byte_add ( core :: mem :: offset_of! ( Self , Some . 0 ) ) . cast ( ) ,
783
783
usize:: from ( self . is_some ( ) ) ,
784
784
)
785
785
}
@@ -835,8 +835,7 @@ impl<T> Option<T> {
835
835
// the `None` case it's just padding).
836
836
unsafe {
837
837
slice:: from_raw_parts_mut (
838
- crate :: intrinsics:: option_payload_ptr ( crate :: ptr:: from_mut ( self ) . cast_const ( ) )
839
- . cast_mut ( ) ,
838
+ ( self as * mut Self ) . byte_add ( core:: mem:: offset_of!( Self , Some . 0 ) ) . cast ( ) ,
840
839
usize:: from ( self . is_some ( ) ) ,
841
840
)
842
841
}
Original file line number Diff line number Diff line change @@ -568,3 +568,11 @@ fn zip_unzip_roundtrip() {
568
568
let a = z. unzip ( ) ;
569
569
assert_eq ! ( a, ( x, y) ) ;
570
570
}
571
+
572
+ #[ test]
573
+ fn as_slice ( ) {
574
+ assert_eq ! ( Some ( 42 ) . as_slice( ) , & [ 42 ] ) ;
575
+ assert_eq ! ( Some ( 43 ) . as_mut_slice( ) , & [ 43 ] ) ;
576
+ assert_eq ! ( None :: <i32 >. as_slice( ) , & [ ] ) ;
577
+ assert_eq ! ( None :: <i32 >. as_mut_slice( ) , & [ ] ) ;
578
+ }
You can’t perform that action at this time.
0 commit comments