144
144
use clone:: Clone ;
145
145
use cmp:: PartialEq ;
146
146
use default:: Default ;
147
- use marker:: { Copy , Send , Sync } ;
147
+ use marker:: { Copy , Send , Sync , Sized } ;
148
148
use ops:: { Deref , DerefMut , Drop } ;
149
149
use option:: Option ;
150
150
use option:: Option :: { None , Some } ;
@@ -266,9 +266,9 @@ impl<T:PartialEq + Copy> PartialEq for Cell<T> {
266
266
///
267
267
/// See the [module-level documentation](index.html) for more.
268
268
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
269
- pub struct RefCell < T > {
270
- value : UnsafeCell < T > ,
269
+ pub struct RefCell < T : ?Sized > {
271
270
borrow : Cell < BorrowFlag > ,
271
+ value : UnsafeCell < T > ,
272
272
}
273
273
274
274
/// An enumeration of values returned from the `state` method on a `RefCell<T>`.
@@ -328,7 +328,9 @@ impl<T> RefCell<T> {
328
328
debug_assert ! ( self . borrow. get( ) == UNUSED ) ;
329
329
unsafe { self . value . into_inner ( ) }
330
330
}
331
+ }
331
332
333
+ impl < T : ?Sized > RefCell < T > {
332
334
/// Query the current state of this `RefCell`
333
335
///
334
336
/// The returned value can be dispatched on to determine if a call to
@@ -449,7 +451,7 @@ impl<T> RefCell<T> {
449
451
}
450
452
451
453
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
452
- unsafe impl < T > Send for RefCell < T > where T : Send { }
454
+ unsafe impl < T : ? Sized > Send for RefCell < T > where T : Send { }
453
455
454
456
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
455
457
impl < T : Clone > Clone for RefCell < T > {
@@ -469,7 +471,7 @@ impl<T:Default> Default for RefCell<T> {
469
471
}
470
472
471
473
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
472
- impl < T : PartialEq > PartialEq for RefCell < T > {
474
+ impl < T : ? Sized + PartialEq > PartialEq for RefCell < T > {
473
475
#[ inline]
474
476
fn eq ( & self , other : & RefCell < T > ) -> bool {
475
477
* self . borrow ( ) == * other. borrow ( )
@@ -520,15 +522,15 @@ impl<'b> Clone for BorrowRef<'b> {
520
522
///
521
523
/// See the [module-level documentation](index.html) for more.
522
524
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
523
- pub struct Ref < ' b , T : ' b > {
525
+ pub struct Ref < ' b , T : ? Sized + ' b > {
524
526
// FIXME #12808: strange name to try to avoid interfering with
525
527
// field accesses of the contained type via Deref
526
528
_value : & ' b T ,
527
529
_borrow : BorrowRef < ' b > ,
528
530
}
529
531
530
532
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
531
- impl < ' b , T > Deref for Ref < ' b , T > {
533
+ impl < ' b , T : ? Sized > Deref for Ref < ' b , T > {
532
534
type Target = T ;
533
535
534
536
#[ inline]
@@ -584,15 +586,15 @@ impl<'b> BorrowRefMut<'b> {
584
586
///
585
587
/// See the [module-level documentation](index.html) for more.
586
588
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
587
- pub struct RefMut < ' b , T : ' b > {
589
+ pub struct RefMut < ' b , T : ? Sized + ' b > {
588
590
// FIXME #12808: strange name to try to avoid interfering with
589
591
// field accesses of the contained type via Deref
590
592
_value : & ' b mut T ,
591
593
_borrow : BorrowRefMut < ' b > ,
592
594
}
593
595
594
596
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
595
- impl < ' b , T > Deref for RefMut < ' b , T > {
597
+ impl < ' b , T : ? Sized > Deref for RefMut < ' b , T > {
596
598
type Target = T ;
597
599
598
600
#[ inline]
@@ -602,7 +604,7 @@ impl<'b, T> Deref for RefMut<'b, T> {
602
604
}
603
605
604
606
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
605
- impl < ' b , T > DerefMut for RefMut < ' b , T > {
607
+ impl < ' b , T : ? Sized > DerefMut for RefMut < ' b , T > {
606
608
#[ inline]
607
609
fn deref_mut < ' a > ( & ' a mut self ) -> & ' a mut T {
608
610
self . _value
@@ -635,7 +637,7 @@ impl<'b, T> DerefMut for RefMut<'b, T> {
635
637
/// recommended to access its fields directly, `get` should be used instead.
636
638
#[ lang="unsafe_cell" ]
637
639
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
638
- pub struct UnsafeCell < T > {
640
+ pub struct UnsafeCell < T : ? Sized > {
639
641
/// Wrapped value
640
642
///
641
643
/// This field should not be accessed directly, it is made public for static
@@ -644,7 +646,7 @@ pub struct UnsafeCell<T> {
644
646
pub value : T ,
645
647
}
646
648
647
- impl < T > !Sync for UnsafeCell < T > { }
649
+ impl < T : ? Sized > !Sync for UnsafeCell < T > { }
648
650
649
651
impl < T > UnsafeCell < T > {
650
652
/// Constructs a new instance of `UnsafeCell` which will wrap the specified
@@ -666,7 +668,12 @@ impl<T> UnsafeCell<T> {
666
668
UnsafeCell { value : value }
667
669
}
668
670
669
- /// Gets a mutable pointer to the wrapped value.
671
+ /// Unwraps the value.
672
+ ///
673
+ /// # Unsafety
674
+ ///
675
+ /// This function is unsafe because there is no guarantee that this or other threads are
676
+ /// currently inspecting the inner value.
670
677
///
671
678
/// # Examples
672
679
///
@@ -675,22 +682,15 @@ impl<T> UnsafeCell<T> {
675
682
///
676
683
/// let uc = UnsafeCell::new(5);
677
684
///
678
- /// let five = uc.get() ;
685
+ /// let five = unsafe { uc.into_inner() } ;
679
686
/// ```
680
687
#[ inline]
681
688
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
682
- pub fn get ( & self ) -> * mut T {
683
- // FIXME(#23542) Replace with type ascription.
684
- #![ allow( trivial_casts) ]
685
- & self . value as * const T as * mut T
686
- }
689
+ pub unsafe fn into_inner ( self ) -> T { self . value }
690
+ }
687
691
688
- /// Unwraps the value.
689
- ///
690
- /// # Unsafety
691
- ///
692
- /// This function is unsafe because there is no guarantee that this or other threads are
693
- /// currently inspecting the inner value.
692
+ impl < T : ?Sized > UnsafeCell < T > {
693
+ /// Gets a mutable pointer to the wrapped value.
694
694
///
695
695
/// # Examples
696
696
///
@@ -699,9 +699,14 @@ impl<T> UnsafeCell<T> {
699
699
///
700
700
/// let uc = UnsafeCell::new(5);
701
701
///
702
- /// let five = unsafe { uc.into_inner() } ;
702
+ /// let five = uc.get() ;
703
703
/// ```
704
704
#[ inline]
705
705
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
706
- pub unsafe fn into_inner ( self ) -> T { self . value }
706
+ pub fn get ( & self ) -> * mut T {
707
+ // FIXME(#23542) Replace with type ascription.
708
+ #![ allow( trivial_casts) ]
709
+ & self . value as * const T as * mut T
710
+ }
711
+
707
712
}
0 commit comments