Skip to content

Commit df2f1fa

Browse files
committed
Remove the _ suffix from slice methods.
Deprecates slicing methods from ImmutableSlice/MutableSlice in favour of slicing syntax or the methods in Slice/SliceMut. Closes #17273.
1 parent 40b9f5d commit df2f1fa

File tree

7 files changed

+188
-97
lines changed

7 files changed

+188
-97
lines changed

src/libcollections/trie.rs

+18
Original file line numberDiff line numberDiff line change
@@ -389,13 +389,22 @@ macro_rules! bound {
389389

390390
impl<T> TrieMap<T> {
391391
// If `upper` is true then returns upper_bound else returns lower_bound.
392+
#[cfg(stage0)]
392393
#[inline]
393394
fn bound<'a>(&'a self, key: uint, upper: bool) -> Entries<'a, T> {
394395
bound!(Entries, self = self,
395396
key = key, is_upper = upper,
396397
slice_from = slice_from_, iter = iter,
397398
mutability = )
398399
}
400+
#[cfg(not(stage0))]
401+
#[inline]
402+
fn bound<'a>(&'a self, key: uint, upper: bool) -> Entries<'a, T> {
403+
bound!(Entries, self = self,
404+
key = key, is_upper = upper,
405+
slice_from = slice_from, iter = iter,
406+
mutability = )
407+
}
399408

400409
/// Gets an iterator pointing to the first key-value pair whose key is not less than `key`.
401410
/// If all keys in the map are less than `key` an empty iterator is returned.
@@ -431,13 +440,22 @@ impl<T> TrieMap<T> {
431440
self.bound(key, true)
432441
}
433442
// If `upper` is true then returns upper_bound else returns lower_bound.
443+
#[cfg(stage0)]
434444
#[inline]
435445
fn bound_mut<'a>(&'a mut self, key: uint, upper: bool) -> MutEntries<'a, T> {
436446
bound!(MutEntries, self = self,
437447
key = key, is_upper = upper,
438448
slice_from = slice_from_mut_, iter = iter_mut,
439449
mutability = mut)
440450
}
451+
#[cfg(not(stage0))]
452+
#[inline]
453+
fn bound_mut<'a>(&'a mut self, key: uint, upper: bool) -> MutEntries<'a, T> {
454+
bound!(MutEntries, self = self,
455+
key = key, is_upper = upper,
456+
slice_from = slice_from_mut, iter = iter_mut,
457+
mutability = mut)
458+
}
441459

442460
/// Deprecated: use `lower_bound_mut`.
443461
#[deprecated = "use lower_bound_mut"]

src/libcollections/vec.rs

+53
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ use core::num;
2323
use core::ops;
2424
use core::ptr;
2525
use core::raw::Slice as RawSlice;
26+
use core::slice::Slice as SliceSlice;
2627
use core::uint;
2728

2829
use {Mutable, MutableSeq};
@@ -459,6 +460,36 @@ impl<T> Index<uint,T> for Vec<T> {
459460
}
460461
}*/
461462

463+
// Annoying helper function because there are two Slice::as_slice functions in
464+
// scope.
465+
#[inline]
466+
fn slice_to_slice<'a, T, U: Slice<T>>(this: &'a U) -> &'a [T] {
467+
this.as_slice()
468+
}
469+
470+
471+
#[cfg(not(stage0))]
472+
impl<T> ops::Slice<uint, [T]> for Vec<T> {
473+
#[inline]
474+
fn as_slice<'a>(&'a self) -> &'a [T] {
475+
slice_to_slice(self)
476+
}
477+
478+
#[inline]
479+
fn slice_from<'a>(&'a self, start: &uint) -> &'a [T] {
480+
slice_to_slice(self).slice_from(start)
481+
}
482+
483+
#[inline]
484+
fn slice_to<'a>(&'a self, end: &uint) -> &'a [T] {
485+
slice_to_slice(self).slice_to(end)
486+
}
487+
#[inline]
488+
fn slice<'a>(&'a self, start: &uint, end: &uint) -> &'a [T] {
489+
slice_to_slice(self).slice(start, end)
490+
}
491+
}
492+
#[cfg(stage0)]
462493
impl<T> ops::Slice<uint, [T]> for Vec<T> {
463494
#[inline]
464495
fn as_slice_<'a>(&'a self) -> &'a [T] {
@@ -480,6 +511,28 @@ impl<T> ops::Slice<uint, [T]> for Vec<T> {
480511
}
481512
}
482513

514+
#[cfg(not(stage0))]
515+
impl<T> ops::SliceMut<uint, [T]> for Vec<T> {
516+
#[inline]
517+
fn as_mut_slice<'a>(&'a mut self) -> &'a mut [T] {
518+
self.as_mut_slice()
519+
}
520+
521+
#[inline]
522+
fn slice_from_mut<'a>(&'a mut self, start: &uint) -> &'a mut [T] {
523+
self.as_mut_slice().slice_from_mut(start)
524+
}
525+
526+
#[inline]
527+
fn slice_to_mut<'a>(&'a mut self, end: &uint) -> &'a mut [T] {
528+
self.as_mut_slice().slice_to_mut(end)
529+
}
530+
#[inline]
531+
fn slice_mut<'a>(&'a mut self, start: &uint, end: &uint) -> &'a mut [T] {
532+
self.as_mut_slice().slice_mut(start, end)
533+
}
534+
}
535+
#[cfg(stage0)]
483536
impl<T> ops::SliceMut<uint, [T]> for Vec<T> {
484537
#[inline]
485538
fn as_mut_slice_<'a>(&'a mut self) -> &'a mut [T] {

src/libcore/ops.rs

+41-10
Original file line numberDiff line numberDiff line change
@@ -688,19 +688,19 @@ pub trait IndexMut<Index, Result> {
688688
* struct Foo;
689689
*
690690
* impl ::core::ops::Slice<Foo, Foo> for Foo {
691-
* fn as_slice_<'a>(&'a self) -> &'a Foo {
691+
* fn as_slice<'a>(&'a self) -> &'a Foo {
692692
* println!("Slicing!");
693693
* self
694694
* }
695-
* fn slice_from_<'a>(&'a self, from: &Foo) -> &'a Foo {
695+
* fn slice_from<'a>(&'a self, from: &Foo) -> &'a Foo {
696696
* println!("Slicing!");
697697
* self
698698
* }
699-
* fn slice_to_<'a>(&'a self, to: &Foo) -> &'a Foo {
699+
* fn slice_to<'a>(&'a self, to: &Foo) -> &'a Foo {
700700
* println!("Slicing!");
701701
* self
702702
* }
703-
* fn slice_<'a>(&'a self, from: &Foo, to: &Foo) -> &'a Foo {
703+
* fn slice<'a>(&'a self, from: &Foo, to: &Foo) -> &'a Foo {
704704
* println!("Slicing!");
705705
* self
706706
* }
@@ -711,7 +711,22 @@ pub trait IndexMut<Index, Result> {
711711
* }
712712
* ```
713713
*/
714-
// FIXME(#17273) remove the postscript _s
714+
#[cfg(not(stage0))]
715+
#[lang="slice"]
716+
pub trait Slice<Idx, Sized? Result> for Sized? {
717+
/// The method for the slicing operation foo[]
718+
fn as_slice<'a>(&'a self) -> &'a Result;
719+
/// The method for the slicing operation foo[from..]
720+
fn slice_from<'a>(&'a self, from: &Idx) -> &'a Result;
721+
/// The method for the slicing operation foo[..to]
722+
fn slice_to<'a>(&'a self, to: &Idx) -> &'a Result;
723+
/// The method for the slicing operation foo[from..to]
724+
fn slice<'a>(&'a self, from: &Idx, to: &Idx) -> &'a Result;
725+
}
726+
/**
727+
*
728+
*/
729+
#[cfg(stage0)]
715730
#[lang="slice"]
716731
pub trait Slice<Idx, Sized? Result> for Sized? {
717732
/// The method for the slicing operation foo[]
@@ -738,19 +753,19 @@ pub trait Slice<Idx, Sized? Result> for Sized? {
738753
* struct Foo;
739754
*
740755
* impl ::core::ops::SliceMut<Foo, Foo> for Foo {
741-
* fn as_mut_slice_<'a>(&'a mut self) -> &'a mut Foo {
756+
* fn as_mut_slice<'a>(&'a mut self) -> &'a mut Foo {
742757
* println!("Slicing!");
743758
* self
744759
* }
745-
* fn slice_from_mut_<'a>(&'a mut self, from: &Foo) -> &'a mut Foo {
760+
* fn slice_from_mut<'a>(&'a mut self, from: &Foo) -> &'a mut Foo {
746761
* println!("Slicing!");
747762
* self
748763
* }
749-
* fn slice_to_mut_<'a>(&'a mut self, to: &Foo) -> &'a mut Foo {
764+
* fn slice_to_mut<'a>(&'a mut self, to: &Foo) -> &'a mut Foo {
750765
* println!("Slicing!");
751766
* self
752767
* }
753-
* fn slice_mut_<'a>(&'a mut self, from: &Foo, to: &Foo) -> &'a mut Foo {
768+
* fn slice_mut<'a>(&'a mut self, from: &Foo, to: &Foo) -> &'a mut Foo {
754769
* println!("Slicing!");
755770
* self
756771
* }
@@ -761,7 +776,22 @@ pub trait Slice<Idx, Sized? Result> for Sized? {
761776
* }
762777
* ```
763778
*/
764-
// FIXME(#17273) remove the postscript _s
779+
#[cfg(not(stage0))]
780+
#[lang="slice_mut"]
781+
pub trait SliceMut<Idx, Sized? Result> for Sized? {
782+
/// The method for the slicing operation foo[]
783+
fn as_mut_slice<'a>(&'a mut self) -> &'a mut Result;
784+
/// The method for the slicing operation foo[from..]
785+
fn slice_from_mut<'a>(&'a mut self, from: &Idx) -> &'a mut Result;
786+
/// The method for the slicing operation foo[..to]
787+
fn slice_to_mut<'a>(&'a mut self, to: &Idx) -> &'a mut Result;
788+
/// The method for the slicing operation foo[from..to]
789+
fn slice_mut<'a>(&'a mut self, from: &Idx, to: &Idx) -> &'a mut Result;
790+
}
791+
/**
792+
*
793+
*/
794+
#[cfg(stage0)]
765795
#[lang="slice_mut"]
766796
pub trait SliceMut<Idx, Sized? Result> for Sized? {
767797
/// The method for the slicing operation foo[mut]
@@ -773,6 +803,7 @@ pub trait SliceMut<Idx, Sized? Result> for Sized? {
773803
/// The method for the slicing operation foo[mut from..to]
774804
fn slice_mut_<'a>(&'a mut self, from: &Idx, to: &Idx) -> &'a mut Result;
775805
}
806+
776807
/**
777808
*
778809
* The `Deref` trait is used to specify the functionality of dereferencing

src/libcore/slice.rs

+58-69
Original file line numberDiff line numberDiff line change
@@ -61,32 +61,6 @@ use raw::Slice as RawSlice;
6161
/// Extension methods for immutable slices.
6262
#[unstable = "may merge with other traits; region parameter may disappear"]
6363
pub trait ImmutableSlice<'a, T> {
64-
/// Returns a subslice spanning the interval [`start`, `end`).
65-
///
66-
/// Fails when the end of the new slice lies beyond the end of the
67-
/// original slice (i.e. when `end > self.len()`) or when `start > end`.
68-
///
69-
/// Slicing with `start` equal to `end` yields an empty slice.
70-
#[unstable = "waiting on final error conventions"]
71-
//fn slice(&self, start: uint, end: uint) -> &'a [T];
72-
73-
/// Returns a subslice from `start` to the end of the slice.
74-
///
75-
/// Fails when `start` is strictly greater than the length of the original slice.
76-
///
77-
/// Slicing from `self.len()` yields an empty slice.
78-
#[unstable = "waiting on final error conventions"]
79-
// TODO
80-
//fn slice_from(&self, start: uint) -> &'a [T];
81-
82-
/// Returns a subslice from the start of the slice to `end`.
83-
///
84-
/// Fails when `end` is strictly greater than the length of the original slice.
85-
///
86-
/// Slicing to `0` yields an empty slice.
87-
#[unstable = "waiting on final error conventions"]
88-
//fn slice_to(&self, end: uint) -> &'a [T];
89-
9064
/// Divides one slice into two at an index.
9165
///
9266
/// The first will contain all indices from `[0, mid)` (excluding
@@ -444,6 +418,35 @@ impl<'a,T> ImmutableSlice<'a, T> for &'a [T] {
444418
}
445419
}
446420

421+
#[cfg(not(stage0))]
422+
impl<T> ops::Slice<uint, [T]> for [T] {
423+
#[inline]
424+
fn as_slice<'a>(&'a self) -> &'a [T] {
425+
self
426+
}
427+
428+
#[inline]
429+
fn slice_from<'a>(&'a self, start: &uint) -> &'a [T] {
430+
self.slice(start, &self.len())
431+
}
432+
433+
#[inline]
434+
fn slice_to<'a>(&'a self, end: &uint) -> &'a [T] {
435+
self.slice(&0, end)
436+
}
437+
#[inline]
438+
fn slice<'a>(&'a self, start: &uint, end: &uint) -> &'a [T] {
439+
assert!(*start <= *end);
440+
assert!(*end <= self.len());
441+
unsafe {
442+
transmute(RawSlice {
443+
data: self.as_ptr().offset(*start as int),
444+
len: (*end - *start)
445+
})
446+
}
447+
}
448+
}
449+
#[cfg(stage0)]
447450
impl<T> ops::Slice<uint, [T]> for [T] {
448451
#[inline]
449452
fn as_slice_<'a>(&'a self) -> &'a [T] {
@@ -471,7 +474,36 @@ impl<T> ops::Slice<uint, [T]> for [T] {
471474
}
472475
}
473476
}
477+
#[cfg(not(stage0))]
478+
impl<T> ops::SliceMut<uint, [T]> for [T] {
479+
#[inline]
480+
fn as_mut_slice<'a>(&'a mut self) -> &'a mut [T] {
481+
self
482+
}
483+
484+
#[inline]
485+
fn slice_from_mut<'a>(&'a mut self, start: &uint) -> &'a mut [T] {
486+
let len = &self.len();
487+
self.slice_mut(start, len)
488+
}
474489

490+
#[inline]
491+
fn slice_to_mut<'a>(&'a mut self, end: &uint) -> &'a mut [T] {
492+
self.slice_mut(&0, end)
493+
}
494+
#[inline]
495+
fn slice_mut<'a>(&'a mut self, start: &uint, end: &uint) -> &'a mut [T] {
496+
assert!(*start <= *end);
497+
assert!(*end <= self.len());
498+
unsafe {
499+
transmute(RawSlice {
500+
data: self.as_ptr().offset(*start as int),
501+
len: (*end - *start)
502+
})
503+
}
504+
}
505+
}
506+
#[cfg(stage0)]
475507
impl<T> ops::SliceMut<uint, [T]> for [T] {
476508
#[inline]
477509
fn as_mut_slice_<'a>(&'a mut self) -> &'a mut [T] {
@@ -514,49 +546,6 @@ pub trait MutableSlice<'a, T> {
514546
#[deprecated = "use slicing syntax"]
515547
fn as_mut_slice(self) -> &'a mut [T];
516548

517-
/// Deprecated: use `slice_mut`.
518-
#[deprecated = "use slicing syntax"]
519-
//fn mut_slice(self, start: uint, end: uint) -> &'a mut [T] {
520-
// self[mut start..end]
521-
//}
522-
523-
/// Returns a mutable subslice spanning the interval [`start`, `end`).
524-
///
525-
/// Fails when the end of the new slice lies beyond the end of the
526-
/// original slice (i.e. when `end > self.len()`) or when `start > end`.
527-
///
528-
/// Slicing with `start` equal to `end` yields an empty slice.
529-
#[unstable = "waiting on final error conventions"]
530-
//fn slice_mut(self, start: uint, end: uint) -> &'a mut [T];
531-
532-
/// Deprecated: use `slicing syntax`.
533-
#[deprecated = "use slicing syntax"]
534-
//fn mut_slice_from(self, start: uint) -> &'a mut [T] {
535-
// self[mut start..]
536-
//}
537-
538-
/// Returns a mutable subslice from `start` to the end of the slice.
539-
///
540-
/// Fails when `start` is strictly greater than the length of the original slice.
541-
///
542-
/// Slicing from `self.len()` yields an empty slice.
543-
#[unstable = "waiting on final error conventions"]
544-
//fn slice_from_mut(self, start: uint) -> &'a mut [T];
545-
546-
/// Deprecated: use `slicing syntax`.
547-
#[deprecated = "use slicing syntax"]
548-
//fn mut_slice_to(self, end: uint) -> &'a mut [T] {
549-
// self[mut ..end]
550-
//}
551-
552-
/// Returns a mutable subslice from the start of the slice to `end`.
553-
///
554-
/// Fails when `end` is strictly greater than the length of the original slice.
555-
///
556-
/// Slicing to `0` yields an empty slice.
557-
#[unstable = "waiting on final error conventions"]
558-
//fn slice_to_mut(self, end: uint) -> &'a mut [T];
559-
560549
/// Deprecated: use `iter_mut`.
561550
#[deprecated = "use iter_mut"]
562551
fn mut_iter(self) -> MutItems<'a, T> {

src/libcoretest/iter.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ fn test_all() {
373373
assert!(v.iter().all(|&x| x < 10));
374374
assert!(!v.iter().all(|&x| x % 2 == 0));
375375
assert!(!v.iter().all(|&x| x > 100));
376-
assert!(v.slice_(&0, &0).iter().all(|_| fail!()));
376+
assert!(v.slice(&0, &0).iter().all(|_| fail!()));
377377
}
378378

379379
#[test]
@@ -382,7 +382,7 @@ fn test_any() {
382382
assert!(v.iter().any(|&x| x < 10));
383383
assert!(v.iter().any(|&x| x % 2 == 0));
384384
assert!(!v.iter().any(|&x| x > 100));
385-
assert!(!v.slice_(&0, &0).iter().any(|_| fail!()));
385+
assert!(!v.slice(&0, &0).iter().any(|_| fail!()));
386386
}
387387

388388
#[test]

0 commit comments

Comments
 (0)