Skip to content

Commit bdf8630

Browse files
committed
impl Deref instead of Index
1 parent 4d99957 commit bdf8630

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

src/libcore/cell.rs

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

207206
/// A mutable memory location.
208207
///
@@ -510,8 +509,9 @@ impl<T: ?Sized> Cell<T> {
510509
/// use std::cell::Cell;
511510
/// let slice: &mut [i32] = &mut [1,2,3];
512511
/// let cell_slice: &Cell<[i32]> = Cell::from_mut(slice);
512+
/// assert_eq!(cell_slice.len(), 3);
513513
/// let slice_cell : &[Cell<i32>] = &cell_slice[..];
514-
/// assert_eq!(slice_cell.len(), 3)
514+
/// assert_eq!(slice_cell.len(), 3);
515515
/// ```
516516
#[inline]
517517
#[unstable(feature = "as_cell", issue="43038")]
@@ -546,15 +546,13 @@ impl<T: Default> Cell<T> {
546546
impl<T: CoerceUnsized<U>, U> CoerceUnsized<Cell<U>> for Cell<T> {}
547547

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

555-
fn index(&self, index: I) -> &Self::Output {
552+
#[inline]
553+
fn deref(&self) -> &[Cell<T>] {
556554
unsafe {
557-
Index::index(&*(self as *const Cell<[T]> as *const [Cell<T>]), index)
555+
&*(self as *const Cell<[T]> as *const [Cell<T>])
558556
}
559557
}
560558
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +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);
1819
let sub_slice : &[Cell<i32>] = &cell_slice[1..];
1920
assert_eq!(sub_slice.len(), 2);
2021
}

0 commit comments

Comments
 (0)