Skip to content

Commit 8812c6b

Browse files
committed
revert Deref
1 parent 7e1b983 commit 8812c6b

File tree

2 files changed

+10
-18
lines changed

2 files changed

+10
-18
lines changed

src/libcore/cell.rs

+9-17
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,9 @@ use cmp::Ordering;
200200
use fmt::{self, Debug, Display};
201201
use marker::Unsize;
202202
use mem;
203-
use ops::{Deref, DerefMut, CoerceUnsized};
203+
use ops::{Deref, DerefMut, CoerceUnsized, Index};
204204
use ptr;
205+
use slice::SliceIndex;
205206

206207
/// A mutable memory location.
207208
///
@@ -510,7 +511,7 @@ impl<T: ?Sized> Cell<T> {
510511
///
511512
/// let slice: &mut [i32] = &mut [1, 2, 3];
512513
/// let cell_slice: &Cell<[i32]> = Cell::from_mut(slice);
513-
/// assert_eq!(cell_slice.len(), 3);
514+
/// assert_eq!(cell_slice[..].len(), 3);
514515
///
515516
/// let slice_cell: &[Cell<i32>] = &cell_slice[..];
516517
/// assert_eq!(slice_cell.len(), 3);
@@ -548,23 +549,14 @@ impl<T: Default> Cell<T> {
548549
impl<T: CoerceUnsized<U>, U> CoerceUnsized<Cell<U>> for Cell<T> {}
549550

550551
#[unstable(feature = "as_cell", issue="43038")]
551-
impl<T> Deref for Cell<[T]> {
552-
type Target = [Cell<T>];
552+
impl<T, I> Index<I> for Cell<[T]>
553+
where I: SliceIndex<[Cell<T>]>
554+
{
555+
type Output = I::Output;
553556

554-
#[inline]
555-
fn deref(&self) -> &[Cell<T>] {
556-
unsafe {
557-
&*(self as *const Cell<[T]> as *const [Cell<T>])
558-
}
559-
}
560-
}
561-
562-
#[unstable(feature = "as_cell", issue="43038")]
563-
impl<T> DerefMut for Cell<[T]> {
564-
#[inline]
565-
fn deref_mut(&mut self) -> &mut [Cell<T>] {
557+
fn index(&self, index: I) -> &Self::Output {
566558
unsafe {
567-
&mut *(self as *mut Cell<[T]> as *mut [Cell<T>])
559+
Index::index(&*(self as *const Cell<[T]> as *const [Cell<T>]), index)
568560
}
569561
}
570562
}

src/test/run-pass/rfc-1789-as-cell/from-mut.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use std::cell::Cell;
1515
fn main() {
1616
let slice: &mut [i32] = &mut [1, 2, 3];
1717
let cell_slice: &Cell<[i32]> = Cell::from_mut(slice);
18-
assert_eq!(cell_slice.len(), 3);
18+
assert_eq!(cell_slice[..].len(), 3);
1919

2020
let sub_slice: &[Cell<i32>] = &cell_slice[1..];
2121
assert_eq!(sub_slice.len(), 2);

0 commit comments

Comments
 (0)