Skip to content

Commit 1a51eb9

Browse files
committed
Auto merge of #21717 - nick29581:prelude-fullrange, r=acrichto
r? @alexcrichton
2 parents e0f5980 + 023d49e commit 1a51eb9

File tree

25 files changed

+219
-89
lines changed

25 files changed

+219
-89
lines changed

src/libcollections/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,9 @@ mod std {
111111
pub use core::option; // necessary for panic!()
112112
pub use core::clone; // derive(Clone)
113113
pub use core::cmp; // derive(Eq, Ord, etc.)
114-
pub use core::marker; // derive(Copy)
114+
pub use core::marker; // derive(Copy)
115115
pub use core::hash; // derive(Hash)
116+
pub use core::ops; // RangeFull
116117
}
117118

118119
#[cfg(test)]

src/libcollections/slice.rs

+6
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,10 @@ use core::iter::{range_step, MultiplicativeIterator};
9898
use core::marker::Sized;
9999
use core::mem::size_of;
100100
use core::mem;
101+
#[cfg(stage0)]
101102
use core::ops::{FnMut, FullRange};
103+
#[cfg(not(stage0))]
104+
use core::ops::FnMut;
102105
use core::option::Option::{self, Some, None};
103106
use core::ptr::PtrExt;
104107
use core::ptr;
@@ -1509,7 +1512,10 @@ mod tests {
15091512
use core::prelude::{Some, None, range, Clone};
15101513
use core::prelude::{Iterator, IteratorExt};
15111514
use core::prelude::{AsSlice};
1515+
#[cfg(stage0)]
15121516
use core::prelude::{Ord, FullRange};
1517+
#[cfg(not(stage0))]
1518+
use core::prelude::Ord;
15131519
use core::default::Default;
15141520
use core::mem;
15151521
use std::iter::RandomAccessIterator;

src/libcollections/str.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,13 @@ use core::char::CharExt;
6060
use core::clone::Clone;
6161
use core::iter::AdditiveIterator;
6262
use core::iter::{Iterator, IteratorExt};
63-
use core::ops::{FullRange, Index};
63+
use core::ops::Index;
64+
#[cfg(stage0)]
65+
use core::ops::FullRange as RangeFull;
66+
#[cfg(stage0)]
67+
use core::ops::FullRange;
68+
#[cfg(not(stage0))]
69+
use core::ops::RangeFull;
6470
use core::option::Option::{self, Some, None};
6571
use core::slice::AsSlice;
6672
use core::str as core_str;
@@ -408,7 +414,7 @@ Section: Trait implementations
408414

409415
/// Any string that can be represented as a slice.
410416
#[stable(feature = "rust1", since = "1.0.0")]
411-
pub trait StrExt: Index<FullRange, Output = str> {
417+
pub trait StrExt: Index<RangeFull, Output = str> {
412418
/// Escapes each char in `s` with `char::escape_default`.
413419
#[unstable(feature = "collections",
414420
reason = "return type may change to be an iterator")]

src/libcollections/string.rs

+11
Original file line numberDiff line numberDiff line change
@@ -877,6 +877,7 @@ impl ops::Index<ops::RangeFrom<uint>> for String {
877877
&self[][*index]
878878
}
879879
}
880+
#[cfg(stage0)]
880881
#[stable(feature = "rust1", since = "1.0.0")]
881882
impl ops::Index<ops::FullRange> for String {
882883
type Output = str;
@@ -885,6 +886,15 @@ impl ops::Index<ops::FullRange> for String {
885886
unsafe { mem::transmute(self.vec.as_slice()) }
886887
}
887888
}
889+
#[cfg(not(stage0))]
890+
#[stable(feature = "rust1", since = "1.0.0")]
891+
impl ops::Index<ops::RangeFull> for String {
892+
type Output = str;
893+
#[inline]
894+
fn index(&self, _index: &ops::RangeFull) -> &str {
895+
unsafe { mem::transmute(self.vec.as_slice()) }
896+
}
897+
}
888898

889899
#[stable(feature = "rust1", since = "1.0.0")]
890900
impl ops::Deref for String {
@@ -995,6 +1005,7 @@ mod tests {
9951005
use str::Utf8Error;
9961006
use core::iter::repeat;
9971007
use super::{as_string, CowString};
1008+
#[cfg(stage0)]
9981009
use core::ops::FullRange;
9991010

10001011
#[test]

src/libcollections/vec.rs

+21
Original file line numberDiff line numberDiff line change
@@ -1317,6 +1317,7 @@ impl<T> ops::Index<ops::RangeFrom<uint>> for Vec<T> {
13171317
self.as_slice().index(index)
13181318
}
13191319
}
1320+
#[cfg(stage0)]
13201321
#[stable(feature = "rust1", since = "1.0.0")]
13211322
impl<T> ops::Index<ops::FullRange> for Vec<T> {
13221323
type Output = [T];
@@ -1325,6 +1326,15 @@ impl<T> ops::Index<ops::FullRange> for Vec<T> {
13251326
self.as_slice()
13261327
}
13271328
}
1329+
#[cfg(not(stage0))]
1330+
#[stable(feature = "rust1", since = "1.0.0")]
1331+
impl<T> ops::Index<ops::RangeFull> for Vec<T> {
1332+
type Output = [T];
1333+
#[inline]
1334+
fn index(&self, _index: &ops::RangeFull) -> &[T] {
1335+
self.as_slice()
1336+
}
1337+
}
13281338

13291339
#[stable(feature = "rust1", since = "1.0.0")]
13301340
impl<T> ops::IndexMut<ops::Range<uint>> for Vec<T> {
@@ -1350,6 +1360,7 @@ impl<T> ops::IndexMut<ops::RangeFrom<uint>> for Vec<T> {
13501360
self.as_mut_slice().index_mut(index)
13511361
}
13521362
}
1363+
#[cfg(stage0)]
13531364
#[stable(feature = "rust1", since = "1.0.0")]
13541365
impl<T> ops::IndexMut<ops::FullRange> for Vec<T> {
13551366
type Output = [T];
@@ -1358,6 +1369,15 @@ impl<T> ops::IndexMut<ops::FullRange> for Vec<T> {
13581369
self.as_mut_slice()
13591370
}
13601371
}
1372+
#[cfg(not(stage0))]
1373+
#[stable(feature = "rust1", since = "1.0.0")]
1374+
impl<T> ops::IndexMut<ops::RangeFull> for Vec<T> {
1375+
type Output = [T];
1376+
#[inline]
1377+
fn index_mut(&mut self, _index: &ops::RangeFull) -> &mut [T] {
1378+
self.as_mut_slice()
1379+
}
1380+
}
13611381

13621382
#[stable(feature = "rust1", since = "1.0.0")]
13631383
impl<T> ops::Deref for Vec<T> {
@@ -1896,6 +1916,7 @@ mod tests {
18961916
use prelude::*;
18971917
use core::mem::size_of;
18981918
use core::iter::repeat;
1919+
#[cfg(stage0)]
18991920
use core::ops::FullRange;
19001921
use test::Bencher;
19011922
use super::as_vec;

src/libcore/array.rs

+3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ use cmp::{PartialEq, Eq, PartialOrd, Ord, Ordering};
1919
use fmt;
2020
use hash::{Hash, Hasher, self};
2121
use marker::Copy;
22+
#[cfg(stage0)]
2223
use ops::{Deref, FullRange};
24+
#[cfg(not(stage0))]
25+
use ops::Deref;
2326
use option::Option;
2427

2528
// macro for implementing n-ary tuple functions and operations

src/libcore/lib.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,9 @@ mod core {
153153
mod std {
154154
pub use clone;
155155
pub use cmp;
156-
pub use marker;
157-
pub use option;
158156
pub use fmt;
159157
pub use hash;
158+
pub use marker;
159+
pub use ops;
160+
pub use option;
160161
}

src/libcore/ops.rs

+17
Original file line numberDiff line numberDiff line change
@@ -947,18 +947,35 @@ pub trait IndexMut<Index: ?Sized> {
947947
}
948948

949949
/// An unbounded range.
950+
#[cfg(stage0)]
950951
#[derive(Copy, Clone, PartialEq, Eq)]
951952
#[lang="full_range"]
952953
#[unstable(feature = "core", reason = "may be renamed to RangeFull")]
953954
pub struct FullRange;
954955

956+
/// An unbounded range.
957+
#[cfg(not(stage0))]
958+
#[derive(Copy, Clone, PartialEq, Eq)]
959+
#[lang="range_full"]
960+
#[stable(feature = "rust1", since = "1.0.0")]
961+
pub struct RangeFull;
962+
963+
#[cfg(stage0)]
955964
#[stable(feature = "rust1", since = "1.0.0")]
956965
impl fmt::Debug for FullRange {
957966
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
958967
fmt::Debug::fmt("..", fmt)
959968
}
960969
}
961970

971+
#[cfg(not(stage0))]
972+
#[stable(feature = "rust1", since = "1.0.0")]
973+
impl fmt::Debug for RangeFull {
974+
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
975+
fmt::Debug::fmt("..", fmt)
976+
}
977+
}
978+
962979
/// A (half-open) range which is bounded at both ends.
963980
#[derive(Copy, Clone, PartialEq, Eq)]
964981
#[lang="range"]

src/libcore/prelude.rs

+3
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@
2626
2727
// Reexported core operators
2828
pub use marker::{Copy, Send, Sized, Sync};
29+
#[cfg(stage0)]
2930
pub use ops::{Drop, Fn, FnMut, FnOnce, FullRange};
31+
#[cfg(not(stage0))]
32+
pub use ops::{Drop, Fn, FnMut, FnOnce};
3033

3134
// Reexported functions
3235
pub use iter::range;

src/libcore/slice.rs

+28-14
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ use iter::*;
4444
use marker::Copy;
4545
use num::Int;
4646
use ops::{FnMut, self, Index};
47+
#[cfg(stage0)]
48+
use ops::FullRange as RangeFull;
49+
#[cfg(not(stage0))]
50+
use ops::RangeFull;
4751
use option::Option;
4852
use option::Option::{None, Some};
4953
use result::Result;
@@ -543,10 +547,10 @@ impl<T> ops::Index<ops::RangeFrom<uint>> for [T] {
543547
}
544548
}
545549
#[stable(feature = "rust1", since = "1.0.0")]
546-
impl<T> ops::Index<ops::FullRange> for [T] {
550+
impl<T> ops::Index<RangeFull> for [T] {
547551
type Output = [T];
548552
#[inline]
549-
fn index(&self, _index: &ops::FullRange) -> &[T] {
553+
fn index(&self, _index: &RangeFull) -> &[T] {
550554
self
551555
}
552556
}
@@ -584,10 +588,10 @@ impl<T> ops::IndexMut<ops::RangeFrom<uint>> for [T] {
584588
}
585589
}
586590
#[stable(feature = "rust1", since = "1.0.0")]
587-
impl<T> ops::IndexMut<ops::FullRange> for [T] {
591+
impl<T> ops::IndexMut<RangeFull> for [T] {
588592
type Output = [T];
589593
#[inline]
590-
fn index_mut(&mut self, _index: &ops::FullRange) -> &mut [T] {
594+
fn index_mut(&mut self, _index: &RangeFull) -> &mut [T] {
591595
self
592596
}
593597
}
@@ -750,6 +754,7 @@ impl<'a, T> ops::Index<ops::RangeFrom<uint>> for Iter<'a, T> {
750754
}
751755
}
752756

757+
#[cfg(stage0)]
753758
#[unstable(feature = "core")]
754759
impl<'a, T> ops::Index<ops::FullRange> for Iter<'a, T> {
755760
type Output = [T];
@@ -758,6 +763,15 @@ impl<'a, T> ops::Index<ops::FullRange> for Iter<'a, T> {
758763
self.as_slice()
759764
}
760765
}
766+
#[cfg(not(stage0))]
767+
#[unstable(feature = "core")]
768+
impl<'a, T> ops::Index<RangeFull> for Iter<'a, T> {
769+
type Output = [T];
770+
#[inline]
771+
fn index(&self, _index: &RangeFull) -> &[T] {
772+
self.as_slice()
773+
}
774+
}
761775

762776
impl<'a, T> Iter<'a, T> {
763777
/// View the underlying data as a subslice of the original data.
@@ -821,30 +835,30 @@ impl<'a, T> ops::Index<ops::Range<uint>> for IterMut<'a, T> {
821835
type Output = [T];
822836
#[inline]
823837
fn index(&self, index: &ops::Range<uint>) -> &[T] {
824-
self.index(&ops::FullRange).index(index)
838+
self.index(&RangeFull).index(index)
825839
}
826840
}
827841
#[unstable(feature = "core")]
828842
impl<'a, T> ops::Index<ops::RangeTo<uint>> for IterMut<'a, T> {
829843
type Output = [T];
830844
#[inline]
831845
fn index(&self, index: &ops::RangeTo<uint>) -> &[T] {
832-
self.index(&ops::FullRange).index(index)
846+
self.index(&RangeFull).index(index)
833847
}
834848
}
835849
#[unstable(feature = "core")]
836850
impl<'a, T> ops::Index<ops::RangeFrom<uint>> for IterMut<'a, T> {
837851
type Output = [T];
838852
#[inline]
839853
fn index(&self, index: &ops::RangeFrom<uint>) -> &[T] {
840-
self.index(&ops::FullRange).index(index)
854+
self.index(&RangeFull).index(index)
841855
}
842856
}
843857
#[unstable(feature = "core")]
844-
impl<'a, T> ops::Index<ops::FullRange> for IterMut<'a, T> {
858+
impl<'a, T> ops::Index<RangeFull> for IterMut<'a, T> {
845859
type Output = [T];
846860
#[inline]
847-
fn index(&self, _index: &ops::FullRange) -> &[T] {
861+
fn index(&self, _index: &RangeFull) -> &[T] {
848862
make_slice!(T => &[T]: self.ptr, self.end)
849863
}
850864
}
@@ -854,30 +868,30 @@ impl<'a, T> ops::IndexMut<ops::Range<uint>> for IterMut<'a, T> {
854868
type Output = [T];
855869
#[inline]
856870
fn index_mut(&mut self, index: &ops::Range<uint>) -> &mut [T] {
857-
self.index_mut(&ops::FullRange).index_mut(index)
871+
self.index_mut(&RangeFull).index_mut(index)
858872
}
859873
}
860874
#[unstable(feature = "core")]
861875
impl<'a, T> ops::IndexMut<ops::RangeTo<uint>> for IterMut<'a, T> {
862876
type Output = [T];
863877
#[inline]
864878
fn index_mut(&mut self, index: &ops::RangeTo<uint>) -> &mut [T] {
865-
self.index_mut(&ops::FullRange).index_mut(index)
879+
self.index_mut(&RangeFull).index_mut(index)
866880
}
867881
}
868882
#[unstable(feature = "core")]
869883
impl<'a, T> ops::IndexMut<ops::RangeFrom<uint>> for IterMut<'a, T> {
870884
type Output = [T];
871885
#[inline]
872886
fn index_mut(&mut self, index: &ops::RangeFrom<uint>) -> &mut [T] {
873-
self.index_mut(&ops::FullRange).index_mut(index)
887+
self.index_mut(&RangeFull).index_mut(index)
874888
}
875889
}
876890
#[unstable(feature = "core")]
877-
impl<'a, T> ops::IndexMut<ops::FullRange> for IterMut<'a, T> {
891+
impl<'a, T> ops::IndexMut<RangeFull> for IterMut<'a, T> {
878892
type Output = [T];
879893
#[inline]
880-
fn index_mut(&mut self, _index: &ops::FullRange) -> &mut [T] {
894+
fn index_mut(&mut self, _index: &RangeFull) -> &mut [T] {
881895
make_slice!(T => &mut [T]: self.ptr, self.end)
882896
}
883897
}

src/libcore/str/mod.rs

+10
Original file line numberDiff line numberDiff line change
@@ -1249,6 +1249,7 @@ mod traits {
12491249
}
12501250
}
12511251

1252+
#[cfg(stage0)]
12521253
#[stable(feature = "rust1", since = "1.0.0")]
12531254
impl ops::Index<ops::FullRange> for str {
12541255
type Output = str;
@@ -1257,6 +1258,15 @@ mod traits {
12571258
self
12581259
}
12591260
}
1261+
#[cfg(not(stage0))]
1262+
#[stable(feature = "rust1", since = "1.0.0")]
1263+
impl ops::Index<ops::RangeFull> for str {
1264+
type Output = str;
1265+
#[inline]
1266+
fn index(&self, _index: &ops::RangeFull) -> &str {
1267+
self
1268+
}
1269+
}
12601270
}
12611271

12621272
/// Any string that can be represented as a slice

src/libcoretest/ops.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// except according to those terms.
1010

1111
use test::Bencher;
12-
use core::ops::{Range, FullRange, RangeFrom, RangeTo};
12+
use core::ops::{Range, RangeFull, RangeFrom, RangeTo};
1313

1414
// Overhead of dtors
1515

@@ -64,5 +64,5 @@ fn test_range_to() {
6464
#[test]
6565
fn test_full_range() {
6666
// Not much to test.
67-
let _ = FullRange;
67+
let _ = RangeFull;
6868
}

src/librustc/middle/lang_items.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ lets_do_this! {
269269
RangeStructLangItem, "range", range_struct;
270270
RangeFromStructLangItem, "range_from", range_from_struct;
271271
RangeToStructLangItem, "range_to", range_to_struct;
272-
FullRangeStructLangItem, "full_range", full_range_struct;
272+
RangeFullStructLangItem, "range_full", range_full_struct;
273273

274274
UnsafeTypeLangItem, "unsafe", unsafe_type;
275275

0 commit comments

Comments
 (0)