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 ( )
@@ -519,15 +521,15 @@ impl<'b> Clone for BorrowRef<'b> {
519
521
///
520
522
/// See the [module-level documentation](index.html) for more.
521
523
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
522
- pub struct Ref < ' b , T : ' b > {
524
+ pub struct Ref < ' b , T : ? Sized + ' b > {
523
525
// FIXME #12808: strange name to try to avoid interfering with
524
526
// field accesses of the contained type via Deref
525
527
_value : & ' b T ,
526
528
_borrow : BorrowRef < ' b > ,
527
529
}
528
530
529
531
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
530
- impl < ' b , T > Deref for Ref < ' b , T > {
532
+ impl < ' b , T : ? Sized > Deref for Ref < ' b , T > {
531
533
type Target = T ;
532
534
533
535
#[ inline]
@@ -582,15 +584,15 @@ impl<'b> BorrowRefMut<'b> {
582
584
///
583
585
/// See the [module-level documentation](index.html) for more.
584
586
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
585
- pub struct RefMut < ' b , T : ' b > {
587
+ pub struct RefMut < ' b , T : ? Sized + ' b > {
586
588
// FIXME #12808: strange name to try to avoid interfering with
587
589
// field accesses of the contained type via Deref
588
590
_value : & ' b mut T ,
589
591
_borrow : BorrowRefMut < ' b > ,
590
592
}
591
593
592
594
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
593
- impl < ' b , T > Deref for RefMut < ' b , T > {
595
+ impl < ' b , T : ? Sized > Deref for RefMut < ' b , T > {
594
596
type Target = T ;
595
597
596
598
#[ inline]
@@ -600,7 +602,7 @@ impl<'b, T> Deref for RefMut<'b, T> {
600
602
}
601
603
602
604
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
603
- impl < ' b , T > DerefMut for RefMut < ' b , T > {
605
+ impl < ' b , T : ? Sized > DerefMut for RefMut < ' b , T > {
604
606
#[ inline]
605
607
fn deref_mut < ' a > ( & ' a mut self ) -> & ' a mut T {
606
608
self . _value
@@ -633,7 +635,7 @@ impl<'b, T> DerefMut for RefMut<'b, T> {
633
635
/// recommended to access its fields directly, `get` should be used instead.
634
636
#[ lang="unsafe_cell" ]
635
637
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
636
- pub struct UnsafeCell < T > {
638
+ pub struct UnsafeCell < T : ? Sized > {
637
639
/// Wrapped value
638
640
///
639
641
/// This field should not be accessed directly, it is made public for static
@@ -642,7 +644,7 @@ pub struct UnsafeCell<T> {
642
644
pub value : T ,
643
645
}
644
646
645
- impl < T > !Sync for UnsafeCell < T > { }
647
+ impl < T : ? Sized > !Sync for UnsafeCell < T > { }
646
648
647
649
impl < T > UnsafeCell < T > {
648
650
/// Constructs a new instance of `UnsafeCell` which will wrap the specified
@@ -664,7 +666,12 @@ impl<T> UnsafeCell<T> {
664
666
UnsafeCell { value : value }
665
667
}
666
668
667
- /// Gets a mutable pointer to the wrapped value.
669
+ /// Unwraps the value.
670
+ ///
671
+ /// # Unsafety
672
+ ///
673
+ /// This function is unsafe because there is no guarantee that this or other threads are
674
+ /// currently inspecting the inner value.
668
675
///
669
676
/// # Examples
670
677
///
@@ -673,22 +680,15 @@ impl<T> UnsafeCell<T> {
673
680
///
674
681
/// let uc = UnsafeCell::new(5);
675
682
///
676
- /// let five = uc.get() ;
683
+ /// let five = unsafe { uc.into_inner() } ;
677
684
/// ```
678
685
#[ inline]
679
686
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
680
- pub fn get ( & self ) -> * mut T {
681
- // FIXME(#23542) Replace with type ascription.
682
- #![ allow( trivial_casts) ]
683
- & self . value as * const T as * mut T
684
- }
687
+ pub unsafe fn into_inner ( self ) -> T { self . value }
688
+ }
685
689
686
- /// Unwraps the value.
687
- ///
688
- /// # Unsafety
689
- ///
690
- /// This function is unsafe because there is no guarantee that this or other threads are
691
- /// currently inspecting the inner value.
690
+ impl < T : ?Sized > UnsafeCell < T > {
691
+ /// Gets a mutable pointer to the wrapped value.
692
692
///
693
693
/// # Examples
694
694
///
@@ -697,9 +697,14 @@ impl<T> UnsafeCell<T> {
697
697
///
698
698
/// let uc = UnsafeCell::new(5);
699
699
///
700
- /// let five = unsafe { uc.into_inner() } ;
700
+ /// let five = uc.get() ;
701
701
/// ```
702
702
#[ inline]
703
703
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
704
- pub unsafe fn into_inner ( self ) -> T { self . value }
704
+ pub fn get ( & self ) -> * mut T {
705
+ // FIXME(#23542) Replace with type ascription.
706
+ #![ allow( trivial_casts) ]
707
+ & self . value as * const T as * mut T
708
+ }
709
+
705
710
}
0 commit comments