Skip to content

Commit 143206d

Browse files
committed
Stabilize RangeArgument
Move it and Bound to core::ops while we're at it. Closes #30877
1 parent dc411e3 commit 143206d

File tree

15 files changed

+187
-217
lines changed

15 files changed

+187
-217
lines changed

src/liballoc/btree/map.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,11 @@ use core::fmt::Debug;
1313
use core::hash::{Hash, Hasher};
1414
use core::iter::{FromIterator, Peekable, FusedIterator};
1515
use core::marker::PhantomData;
16-
use core::ops::Index;
16+
use core::ops::{Index, RangeArgument};
17+
use core::ops::Bound::{Excluded, Included, Unbounded};
1718
use core::{fmt, intrinsics, mem, ptr};
1819

1920
use borrow::Borrow;
20-
use Bound::{Excluded, Included, Unbounded};
21-
use range::RangeArgument;
2221

2322
use super::node::{self, Handle, NodeRef, marker};
2423
use super::search;

src/liballoc/btree/set.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,11 @@ use core::cmp::{min, max};
1616
use core::fmt::Debug;
1717
use core::fmt;
1818
use core::iter::{Peekable, FromIterator, FusedIterator};
19-
use core::ops::{BitOr, BitAnd, BitXor, Sub};
19+
use core::ops::{BitOr, BitAnd, BitXor, Sub, RangeArgument};
2020

2121
use borrow::Borrow;
2222
use btree_map::{BTreeMap, Keys};
2323
use super::Recover;
24-
use range::RangeArgument;
2524

2625
// FIXME(conventions): implement bounded iterators
2726

src/liballoc/lib.rs

+1-50
Original file line numberDiff line numberDiff line change
@@ -203,56 +203,7 @@ mod std {
203203
pub use core::ops; // RangeFull
204204
}
205205

206-
/// An endpoint of a range of keys.
207-
///
208-
/// # Examples
209-
///
210-
/// `Bound`s are range endpoints:
211-
///
212-
/// ```
213-
/// #![feature(collections_range)]
214-
///
215-
/// use std::collections::range::RangeArgument;
216-
/// use std::collections::Bound::*;
217-
///
218-
/// assert_eq!((..100).start(), Unbounded);
219-
/// assert_eq!((1..12).start(), Included(&1));
220-
/// assert_eq!((1..12).end(), Excluded(&12));
221-
/// ```
222-
///
223-
/// Using a tuple of `Bound`s as an argument to [`BTreeMap::range`].
224-
/// Note that in most cases, it's better to use range syntax (`1..5`) instead.
225-
///
226-
/// ```
227-
/// use std::collections::BTreeMap;
228-
/// use std::collections::Bound::{Excluded, Included, Unbounded};
229-
///
230-
/// let mut map = BTreeMap::new();
231-
/// map.insert(3, "a");
232-
/// map.insert(5, "b");
233-
/// map.insert(8, "c");
234-
///
235-
/// for (key, value) in map.range((Excluded(3), Included(8))) {
236-
/// println!("{}: {}", key, value);
237-
/// }
238-
///
239-
/// assert_eq!(Some((&3, &"a")), map.range((Unbounded, Included(5))).next());
240-
/// ```
241-
///
242-
/// [`BTreeMap::range`]: btree_map/struct.BTreeMap.html#method.range
243-
#[stable(feature = "collections_bound", since = "1.17.0")]
244-
#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq)]
245-
pub enum Bound<T> {
246-
/// An inclusive bound.
247-
#[stable(feature = "collections_bound", since = "1.17.0")]
248-
Included(T),
249-
/// An exclusive bound.
250-
#[stable(feature = "collections_bound", since = "1.17.0")]
251-
Excluded(T),
252-
/// An infinite endpoint. Indicates that there is no bound in this direction.
253-
#[stable(feature = "collections_bound", since = "1.17.0")]
254-
Unbounded,
255-
}
206+
pub use core::ops::Bound;
256207

257208
/// An intermediate trait for specialization of `Extend`.
258209
#[doc(hidden)]

src/liballoc/range.rs

+2-136
Original file line numberDiff line numberDiff line change
@@ -11,142 +11,8 @@
1111
#![unstable(feature = "collections_range",
1212
reason = "waiting for dust to settle on inclusive ranges",
1313
issue = "30877")]
14+
#![rustc_deprecated(reason = "moved to core::ops", since = "1.19.0")]
1415

1516
//! Range syntax.
1617
17-
use core::ops::{RangeFull, Range, RangeTo, RangeFrom, RangeInclusive, RangeToInclusive};
18-
use Bound::{self, Excluded, Included, Unbounded};
19-
20-
/// `RangeArgument` is implemented by Rust's built-in range types, produced
21-
/// by range syntax like `..`, `a..`, `..b` or `c..d`.
22-
pub trait RangeArgument<T: ?Sized> {
23-
/// Start index bound.
24-
///
25-
/// Returns the start value as a `Bound`.
26-
///
27-
/// # Examples
28-
///
29-
/// ```
30-
/// #![feature(alloc)]
31-
/// #![feature(collections_range)]
32-
///
33-
/// extern crate alloc;
34-
///
35-
/// # fn main() {
36-
/// use alloc::range::RangeArgument;
37-
/// use alloc::Bound::*;
38-
///
39-
/// assert_eq!((..10).start(), Unbounded);
40-
/// assert_eq!((3..10).start(), Included(&3));
41-
/// # }
42-
/// ```
43-
fn start(&self) -> Bound<&T>;
44-
45-
/// End index bound.
46-
///
47-
/// Returns the end value as a `Bound`.
48-
///
49-
/// # Examples
50-
///
51-
/// ```
52-
/// #![feature(alloc)]
53-
/// #![feature(collections_range)]
54-
///
55-
/// extern crate alloc;
56-
///
57-
/// # fn main() {
58-
/// use alloc::range::RangeArgument;
59-
/// use alloc::Bound::*;
60-
///
61-
/// assert_eq!((3..).end(), Unbounded);
62-
/// assert_eq!((3..10).end(), Excluded(&10));
63-
/// # }
64-
/// ```
65-
fn end(&self) -> Bound<&T>;
66-
}
67-
68-
// FIXME add inclusive ranges to RangeArgument
69-
70-
impl<T: ?Sized> RangeArgument<T> for RangeFull {
71-
fn start(&self) -> Bound<&T> {
72-
Unbounded
73-
}
74-
fn end(&self) -> Bound<&T> {
75-
Unbounded
76-
}
77-
}
78-
79-
impl<T> RangeArgument<T> for RangeFrom<T> {
80-
fn start(&self) -> Bound<&T> {
81-
Included(&self.start)
82-
}
83-
fn end(&self) -> Bound<&T> {
84-
Unbounded
85-
}
86-
}
87-
88-
impl<T> RangeArgument<T> for RangeTo<T> {
89-
fn start(&self) -> Bound<&T> {
90-
Unbounded
91-
}
92-
fn end(&self) -> Bound<&T> {
93-
Excluded(&self.end)
94-
}
95-
}
96-
97-
impl<T> RangeArgument<T> for Range<T> {
98-
fn start(&self) -> Bound<&T> {
99-
Included(&self.start)
100-
}
101-
fn end(&self) -> Bound<&T> {
102-
Excluded(&self.end)
103-
}
104-
}
105-
106-
#[unstable(feature = "inclusive_range", reason = "recently added, follows RFC", issue = "28237")]
107-
impl<T> RangeArgument<T> for RangeInclusive<T> {
108-
fn start(&self) -> Bound<&T> {
109-
Included(&self.start)
110-
}
111-
fn end(&self) -> Bound<&T> {
112-
Included(&self.end)
113-
}
114-
}
115-
116-
#[unstable(feature = "inclusive_range", reason = "recently added, follows RFC", issue = "28237")]
117-
impl<T> RangeArgument<T> for RangeToInclusive<T> {
118-
fn start(&self) -> Bound<&T> {
119-
Unbounded
120-
}
121-
fn end(&self) -> Bound<&T> {
122-
Included(&self.end)
123-
}
124-
}
125-
126-
impl<T> RangeArgument<T> for (Bound<T>, Bound<T>) {
127-
fn start(&self) -> Bound<&T> {
128-
match *self {
129-
(Included(ref start), _) => Included(start),
130-
(Excluded(ref start), _) => Excluded(start),
131-
(Unbounded, _) => Unbounded,
132-
}
133-
}
134-
135-
fn end(&self) -> Bound<&T> {
136-
match *self {
137-
(_, Included(ref end)) => Included(end),
138-
(_, Excluded(ref end)) => Excluded(end),
139-
(_, Unbounded) => Unbounded,
140-
}
141-
}
142-
}
143-
144-
impl<'a, T: ?Sized + 'a> RangeArgument<T> for (Bound<&'a T>, Bound<&'a T>) {
145-
fn start(&self) -> Bound<&T> {
146-
self.0
147-
}
148-
149-
fn end(&self) -> Bound<&T> {
150-
self.1
151-
}
152-
}
18+
pub use core::ops::RangeArgument;

src/liballoc/string.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,14 @@
5959
use core::fmt;
6060
use core::hash;
6161
use core::iter::{FromIterator, FusedIterator};
62-
use core::ops::{self, Add, AddAssign, Index, IndexMut};
62+
use core::ops::{self, Add, AddAssign, Index, IndexMut, RangeArgument};
63+
use core::ops::Bound::{Excluded, Included, Unbounded};
6364
use core::ptr;
6465
use core::str::pattern::Pattern;
6566
use std_unicode::lossy;
6667
use std_unicode::char::{decode_utf16, REPLACEMENT_CHARACTER};
6768

6869
use borrow::{Cow, ToOwned};
69-
use range::RangeArgument;
70-
use Bound::{Excluded, Included, Unbounded};
7170
use str::{self, from_boxed_utf8_unchecked, FromStr, Utf8Error, Chars};
7271
use vec::Vec;
7372
use boxed::Box;

src/liballoc/vec.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ use core::iter::{FromIterator, FusedIterator, TrustedLen};
7474
use core::mem;
7575
#[cfg(not(test))]
7676
use core::num::Float;
77-
use core::ops::{InPlace, Index, IndexMut, Place, Placer};
77+
use core::ops::{InPlace, Index, IndexMut, Place, Placer, RangeArgument};
78+
use core::ops::Bound::{Excluded, Included, Unbounded};
7879
use core::ops;
7980
use core::ptr;
8081
use core::ptr::Shared;
@@ -84,8 +85,6 @@ use borrow::ToOwned;
8485
use borrow::Cow;
8586
use boxed::Box;
8687
use raw_vec::RawVec;
87-
use super::range::RangeArgument;
88-
use Bound::{Excluded, Included, Unbounded};
8988

9089
/// A contiguous growable array type, written `Vec<T>` but pronounced 'vector'.
9190
///

src/liballoc/vec_deque.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ use core::cmp::Ordering;
2121
use core::fmt;
2222
use core::iter::{repeat, FromIterator, FusedIterator};
2323
use core::mem;
24-
use core::ops::{Index, IndexMut, Place, Placer, InPlace};
24+
use core::ops::{Index, IndexMut, Place, Placer, InPlace, RangeArgument};
25+
use core::ops::Bound::{Excluded, Included, Unbounded};
2526
use core::ptr;
2627
use core::ptr::Shared;
2728
use core::slice;
@@ -31,8 +32,6 @@ use core::cmp;
3132

3233
use raw_vec::RawVec;
3334

34-
use super::range::RangeArgument;
35-
use Bound::{Excluded, Included, Unbounded};
3635
use super::vec::Vec;
3736

3837
const INITIAL_CAPACITY: usize = 7; // 2^3 - 1

src/libcollections/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ pub use alloc::binary_heap;
4646
pub use alloc::borrow;
4747
pub use alloc::fmt;
4848
pub use alloc::linked_list;
49+
#[allow(deprecated)]
4950
pub use alloc::range;
5051
pub use alloc::slice;
5152
pub use alloc::str;

src/libcore/ops/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,9 @@ pub use self::index::{Index, IndexMut};
183183
#[stable(feature = "rust1", since = "1.0.0")]
184184
pub use self::range::{Range, RangeFrom, RangeFull, RangeTo};
185185

186+
#[stable(feature = "range_argument", since = "1.19.0")]
187+
pub use self::range::{RangeArgument, Bound};
188+
186189
#[unstable(feature = "inclusive_range", reason = "recently added, follows RFC", issue = "28237")]
187190
pub use self::range::{RangeInclusive, RangeToInclusive};
188191

0 commit comments

Comments
 (0)