File tree 6 files changed +47
-0
lines changed
6 files changed +47
-0
lines changed Original file line number Diff line number Diff line change @@ -527,6 +527,15 @@ impl From<Box<str>> for Box<[u8]> {
527
527
}
528
528
}
529
529
530
+ #[ allow( incoherent_fundamental_impls) ]
531
+ #[ unstable( feature = "box_into_raw_non_null" , issue = "47336" ) ]
532
+ impl < T : ?Sized > Into < NonNull < T > > for Box < T > {
533
+ #[ inline]
534
+ fn into ( self ) -> NonNull < T > {
535
+ Box :: into_unique ( self ) . into ( )
536
+ }
537
+ }
538
+
530
539
impl Box < dyn Any > {
531
540
#[ inline]
532
541
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
Original file line number Diff line number Diff line change @@ -138,3 +138,11 @@ fn boxed_slice_from_iter() {
138
138
assert_eq ! ( boxed. len( ) , 100 ) ;
139
139
assert_eq ! ( boxed[ 7 ] , 7 ) ;
140
140
}
141
+
142
+ #[ test]
143
+ fn to_nonnull ( ) {
144
+ let boxed: Box < i32 > = Box :: from ( 0 ) ;
145
+ let ptr: std:: ptr:: NonNull < i32 > = boxed. into ( ) ;
146
+ let deref = unsafe { * ptr. as_ref ( ) } ;
147
+ assert_eq ! ( deref, 0 ) ;
148
+ }
Original file line number Diff line number Diff line change @@ -1176,6 +1176,14 @@ impl<T> From<Vec<T>> for Rc<[T]> {
1176
1176
}
1177
1177
}
1178
1178
1179
+ #[ unstable( feature = "rc_into_nonnull" , reason = "newly added" , issue = "0" ) ]
1180
+ impl < T : ?Sized > Into < NonNull < T > > for Rc < T > {
1181
+ #[ inline]
1182
+ fn into ( self ) -> NonNull < T > {
1183
+ unsafe { NonNull :: new_unchecked ( Rc :: into_raw ( self ) as * mut _ ) }
1184
+ }
1185
+ }
1186
+
1179
1187
/// `Weak` is a version of [`Rc`] that holds a non-owning reference to the
1180
1188
/// managed value. The value is accessed by calling [`upgrade`] on the `Weak`
1181
1189
/// pointer, which returns an [`Option`]`<`[`Rc`]`<T>>`.
Original file line number Diff line number Diff line change @@ -1572,6 +1572,14 @@ impl<T> From<Vec<T>> for Arc<[T]> {
1572
1572
}
1573
1573
}
1574
1574
1575
+ #[ unstable( feature = "arc_into_nonnull" , reason = "newly added" , issue = "0" ) ]
1576
+ impl < T : ?Sized > Into < NonNull < T > > for Arc < T > {
1577
+ #[ inline]
1578
+ fn into ( self ) -> NonNull < T > {
1579
+ unsafe { NonNull :: new_unchecked ( Arc :: into_raw ( self ) as * mut _ ) }
1580
+ }
1581
+ }
1582
+
1575
1583
#[ cfg( test) ]
1576
1584
mod tests {
1577
1585
use std:: boxed:: Box ;
Original file line number Diff line number Diff line change @@ -85,3 +85,10 @@ fn eq() {
85
85
assert ! ( !( x != x) ) ;
86
86
assert_eq ! ( * x. 0 . borrow( ) , 0 ) ;
87
87
}
88
+
89
+ #[ test]
90
+ fn to_nonnull ( ) {
91
+ let ptr: std:: ptr:: NonNull < i32 > = Arc :: new ( 0 ) . into ( ) ;
92
+ let deref = unsafe { * ptr. as_ref ( ) } ;
93
+ assert_eq ! ( deref, 0 ) ;
94
+ }
Original file line number Diff line number Diff line change @@ -85,3 +85,10 @@ fn eq() {
85
85
assert ! ( !( x != x) ) ;
86
86
assert_eq ! ( * x. 0 . borrow( ) , 0 ) ;
87
87
}
88
+
89
+ #[ test]
90
+ fn to_nonnull ( ) {
91
+ let ptr: std:: ptr:: NonNull < i32 > = Rc :: new ( 0 ) . into ( ) ;
92
+ let deref = unsafe { * ptr. as_ref ( ) } ;
93
+ assert_eq ! ( deref, 0 ) ;
94
+ }
You can’t perform that action at this time.
0 commit comments