Skip to content

Commit ae544ee

Browse files
committed
Auto merge of #49163 - SimonSapin:range-bounds, r=alexcrichton
Rename RangeArgument to RangeBounds, move it and Bound to libcore As proposed in the tracking issue: #30877 Changes to *stable* items: * `core::ops::Bound` / `std::ops::Bound` is new * `std::collections::Bound` is a deprecated reexport of it (does this actually cause a warning?) Changes to *unstable* items * `alloc::Bound` is gone * `alloc::range::RangeArgument` is moved to `core::ops::RangeBounds` / `std::ops::RangeBounds` * `alloc::range` is gone * `std::collections::range::RangeArgument` is deprecated reexport, to be removed later * `std::collections::range` is deprecated, to be removed later * `impl RangeBounds<T> for Range{,From,To,Inclusive,ToInclusive}<&T>` are added The idea of replacing this trait with a type to be used with `Into<_>` is left for future consideration / work. (Fixes rust-lang/rust-clippy#2552.)
2 parents 409744b + 6c9b3cc commit ae544ee

File tree

16 files changed

+307
-245
lines changed

16 files changed

+307
-245
lines changed

src/liballoc/btree/map.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ 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::Bound::{Excluded, Included, Unbounded};
1617
use core::ops::Index;
18+
use core::ops::RangeBounds;
1719
use core::{fmt, intrinsics, mem, ptr};
1820

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

2323
use super::node::{self, Handle, NodeRef, marker};
2424
use super::search;
@@ -804,7 +804,7 @@ impl<K: Ord, V> BTreeMap<K, V> {
804804
///
805805
/// ```
806806
/// use std::collections::BTreeMap;
807-
/// use std::collections::Bound::Included;
807+
/// use std::ops::Bound::Included;
808808
///
809809
/// let mut map = BTreeMap::new();
810810
/// map.insert(3, "a");
@@ -817,7 +817,7 @@ impl<K: Ord, V> BTreeMap<K, V> {
817817
/// ```
818818
#[stable(feature = "btree_range", since = "1.17.0")]
819819
pub fn range<T: ?Sized, R>(&self, range: R) -> Range<K, V>
820-
where T: Ord, K: Borrow<T>, R: RangeArgument<T>
820+
where T: Ord, K: Borrow<T>, R: RangeBounds<T>
821821
{
822822
let root1 = self.root.as_ref();
823823
let root2 = self.root.as_ref();
@@ -857,7 +857,7 @@ impl<K: Ord, V> BTreeMap<K, V> {
857857
/// ```
858858
#[stable(feature = "btree_range", since = "1.17.0")]
859859
pub fn range_mut<T: ?Sized, R>(&mut self, range: R) -> RangeMut<K, V>
860-
where T: Ord, K: Borrow<T>, R: RangeArgument<T>
860+
where T: Ord, K: Borrow<T>, R: RangeBounds<T>
861861
{
862862
let root1 = self.root.as_mut();
863863
let root2 = unsafe { ptr::read(&root1) };
@@ -1812,7 +1812,7 @@ fn last_leaf_edge<BorrowType, K, V>
18121812
}
18131813
}
18141814

1815-
fn range_search<BorrowType, K, V, Q: ?Sized, R: RangeArgument<Q>>(
1815+
fn range_search<BorrowType, K, V, Q: ?Sized, R: RangeBounds<Q>>(
18161816
root1: NodeRef<BorrowType, K, V, marker::LeafOrInternal>,
18171817
root2: NodeRef<BorrowType, K, V, marker::LeafOrInternal>,
18181818
range: R

src/liballoc/btree/set.rs

+3-4
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, RangeBounds};
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

@@ -240,7 +239,7 @@ impl<T: Ord> BTreeSet<T> {
240239
///
241240
/// ```
242241
/// use std::collections::BTreeSet;
243-
/// use std::collections::Bound::Included;
242+
/// use std::ops::Bound::Included;
244243
///
245244
/// let mut set = BTreeSet::new();
246245
/// set.insert(3);
@@ -253,7 +252,7 @@ impl<T: Ord> BTreeSet<T> {
253252
/// ```
254253
#[stable(feature = "btree_range", since = "1.17.0")]
255254
pub fn range<K: ?Sized, R>(&self, range: R) -> Range<T>
256-
where K: Ord, T: Borrow<K>, R: RangeArgument<K>
255+
where K: Ord, T: Borrow<K>, R: RangeBounds<K>
257256
{
258257
Range { iter: self.map.range(range) }
259258
}

src/liballoc/lib.rs

+1-52
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@
8888
#![feature(box_syntax)]
8989
#![feature(cfg_target_has_atomic)]
9090
#![feature(coerce_unsized)]
91+
#![feature(collections_range)]
9192
#![feature(const_fn)]
9293
#![feature(core_intrinsics)]
9394
#![feature(custom_attribute)]
@@ -178,7 +179,6 @@ mod btree;
178179
pub mod borrow;
179180
pub mod fmt;
180181
pub mod linked_list;
181-
pub mod range;
182182
pub mod slice;
183183
pub mod str;
184184
pub mod string;
@@ -204,57 +204,6 @@ mod std {
204204
pub use core::ops; // RangeFull
205205
}
206206

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

src/liballoc/range.rs

-152
This file was deleted.

src/liballoc/string.rs

+4-5
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::Bound::{Excluded, Included, Unbounded};
63+
use core::ops::{self, Add, AddAssign, Index, IndexMut, RangeBounds};
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;
@@ -1484,7 +1483,7 @@ impl String {
14841483
/// ```
14851484
#[stable(feature = "drain", since = "1.6.0")]
14861485
pub fn drain<R>(&mut self, range: R) -> Drain
1487-
where R: RangeArgument<usize>
1486+
where R: RangeBounds<usize>
14881487
{
14891488
// Memory safety
14901489
//
@@ -1548,7 +1547,7 @@ impl String {
15481547
/// ```
15491548
#[unstable(feature = "splice", reason = "recently added", issue = "44643")]
15501549
pub fn splice<R>(&mut self, range: R, replace_with: &str)
1551-
where R: RangeArgument<usize>
1550+
where R: RangeBounds<usize>
15521551
{
15531552
// Memory safety
15541553
//

src/liballoc/tests/btree/map.rs

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

1111
use std::collections::BTreeMap;
12-
use std::collections::Bound::{self, Excluded, Included, Unbounded};
1312
use std::collections::btree_map::Entry::{Occupied, Vacant};
13+
use std::ops::Bound::{self, Excluded, Included, Unbounded};
1414
use std::rc::Rc;
1515

1616
use std::iter::FromIterator;

src/liballoc/vec.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ use core::marker::PhantomData;
7575
use core::mem;
7676
#[cfg(not(test))]
7777
use core::num::Float;
78-
use core::ops::{InPlace, Index, IndexMut, Place, Placer};
78+
use core::ops::Bound::{Excluded, Included, Unbounded};
79+
use core::ops::{InPlace, Index, IndexMut, Place, Placer, RangeBounds};
7980
use core::ops;
8081
use core::ptr;
8182
use core::ptr::NonNull;
@@ -85,9 +86,7 @@ use borrow::ToOwned;
8586
use borrow::Cow;
8687
use boxed::Box;
8788
use raw_vec::RawVec;
88-
use super::range::RangeArgument;
8989
use super::allocator::CollectionAllocErr;
90-
use Bound::{Excluded, Included, Unbounded};
9190

9291
/// A contiguous growable array type, written `Vec<T>` but pronounced 'vector'.
9392
///
@@ -1176,7 +1175,7 @@ impl<T> Vec<T> {
11761175
/// ```
11771176
#[stable(feature = "drain", since = "1.6.0")]
11781177
pub fn drain<R>(&mut self, range: R) -> Drain<T>
1179-
where R: RangeArgument<usize>
1178+
where R: RangeBounds<usize>
11801179
{
11811180
// Memory safety
11821181
//
@@ -1950,7 +1949,7 @@ impl<T> Vec<T> {
19501949
#[inline]
19511950
#[stable(feature = "vec_splice", since = "1.21.0")]
19521951
pub fn splice<R, I>(&mut self, range: R, replace_with: I) -> Splice<I::IntoIter>
1953-
where R: RangeArgument<usize>, I: IntoIterator<Item=T>
1952+
where R: RangeBounds<usize>, I: IntoIterator<Item=T>
19541953
{
19551954
Splice {
19561955
drain: self.drain(range),

0 commit comments

Comments
 (0)