144144use clone:: Clone ;
145145use cmp:: PartialEq ;
146146use default:: Default ;
147- use marker:: { Copy , Send , Sync } ;
147+ use marker:: { Copy , Send , Sync , Sized } ;
148148use ops:: { Deref , DerefMut , Drop } ;
149149use option:: Option ;
150150use option:: Option :: { None , Some } ;
@@ -266,9 +266,9 @@ impl<T:PartialEq + Copy> PartialEq for Cell<T> {
266266///
267267/// See the [module-level documentation](index.html) for more.
268268#[ stable( feature = "rust1" , since = "1.0.0" ) ]
269- pub struct RefCell < T > {
270- value : UnsafeCell < T > ,
269+ pub struct RefCell < T : ?Sized > {
271270 borrow : Cell < BorrowFlag > ,
271+ value : UnsafeCell < T > ,
272272}
273273
274274/// An enumeration of values returned from the `state` method on a `RefCell<T>`.
@@ -328,7 +328,9 @@ impl<T> RefCell<T> {
328328 debug_assert ! ( self . borrow. get( ) == UNUSED ) ;
329329 unsafe { self . value . into_inner ( ) }
330330 }
331+ }
331332
333+ impl < T : ?Sized > RefCell < T > {
332334 /// Query the current state of this `RefCell`
333335 ///
334336 /// The returned value can be dispatched on to determine if a call to
@@ -449,7 +451,7 @@ impl<T> RefCell<T> {
449451}
450452
451453#[ 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 { }
453455
454456#[ stable( feature = "rust1" , since = "1.0.0" ) ]
455457impl < T : Clone > Clone for RefCell < T > {
@@ -469,7 +471,7 @@ impl<T:Default> Default for RefCell<T> {
469471}
470472
471473#[ stable( feature = "rust1" , since = "1.0.0" ) ]
472- impl < T : PartialEq > PartialEq for RefCell < T > {
474+ impl < T : ? Sized + PartialEq > PartialEq for RefCell < T > {
473475 #[ inline]
474476 fn eq ( & self , other : & RefCell < T > ) -> bool {
475477 * self . borrow ( ) == * other. borrow ( )
@@ -520,15 +522,15 @@ impl<'b> Clone for BorrowRef<'b> {
520522///
521523/// See the [module-level documentation](index.html) for more.
522524#[ stable( feature = "rust1" , since = "1.0.0" ) ]
523- pub struct Ref < ' b , T : ' b > {
525+ pub struct Ref < ' b , T : ? Sized + ' b > {
524526 // FIXME #12808: strange name to try to avoid interfering with
525527 // field accesses of the contained type via Deref
526528 _value : & ' b T ,
527529 _borrow : BorrowRef < ' b > ,
528530}
529531
530532#[ 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 > {
532534 type Target = T ;
533535
534536 #[ inline]
@@ -584,15 +586,15 @@ impl<'b> BorrowRefMut<'b> {
584586///
585587/// See the [module-level documentation](index.html) for more.
586588#[ stable( feature = "rust1" , since = "1.0.0" ) ]
587- pub struct RefMut < ' b , T : ' b > {
589+ pub struct RefMut < ' b , T : ? Sized + ' b > {
588590 // FIXME #12808: strange name to try to avoid interfering with
589591 // field accesses of the contained type via Deref
590592 _value : & ' b mut T ,
591593 _borrow : BorrowRefMut < ' b > ,
592594}
593595
594596#[ 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 > {
596598 type Target = T ;
597599
598600 #[ inline]
@@ -602,7 +604,7 @@ impl<'b, T> Deref for RefMut<'b, T> {
602604}
603605
604606#[ 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 > {
606608 #[ inline]
607609 fn deref_mut < ' a > ( & ' a mut self ) -> & ' a mut T {
608610 self . _value
@@ -635,7 +637,7 @@ impl<'b, T> DerefMut for RefMut<'b, T> {
635637/// recommended to access its fields directly, `get` should be used instead.
636638#[ lang="unsafe_cell" ]
637639#[ stable( feature = "rust1" , since = "1.0.0" ) ]
638- pub struct UnsafeCell < T > {
640+ pub struct UnsafeCell < T : ? Sized > {
639641 /// Wrapped value
640642 ///
641643 /// This field should not be accessed directly, it is made public for static
@@ -644,7 +646,7 @@ pub struct UnsafeCell<T> {
644646 pub value : T ,
645647}
646648
647- impl < T > !Sync for UnsafeCell < T > { }
649+ impl < T : ? Sized > !Sync for UnsafeCell < T > { }
648650
649651impl < T > UnsafeCell < T > {
650652 /// Constructs a new instance of `UnsafeCell` which will wrap the specified
@@ -666,7 +668,12 @@ impl<T> UnsafeCell<T> {
666668 UnsafeCell { value : value }
667669 }
668670
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.
670677 ///
671678 /// # Examples
672679 ///
@@ -675,22 +682,15 @@ impl<T> UnsafeCell<T> {
675682 ///
676683 /// let uc = UnsafeCell::new(5);
677684 ///
678- /// let five = uc.get() ;
685+ /// let five = unsafe { uc.into_inner() } ;
679686 /// ```
680687 #[ inline]
681688 #[ 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+ }
687691
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.
694694 ///
695695 /// # Examples
696696 ///
@@ -699,9 +699,14 @@ impl<T> UnsafeCell<T> {
699699 ///
700700 /// let uc = UnsafeCell::new(5);
701701 ///
702- /// let five = unsafe { uc.into_inner() } ;
702+ /// let five = uc.get() ;
703703 /// ```
704704 #[ inline]
705705 #[ 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+
707712}
0 commit comments