Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename RangeArgument to RangeBounds, move it and Bound to libcore #49163

Merged
merged 6 commits into from
Mar 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/liballoc/btree/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ use core::fmt::Debug;
use core::hash::{Hash, Hasher};
use core::iter::{FromIterator, Peekable, FusedIterator};
use core::marker::PhantomData;
use core::ops::Bound::{Excluded, Included, Unbounded};
use core::ops::Index;
use core::ops::RangeBounds;
use core::{fmt, intrinsics, mem, ptr};

use borrow::Borrow;
use Bound::{Excluded, Included, Unbounded};
use range::RangeArgument;

use super::node::{self, Handle, NodeRef, marker};
use super::search;
Expand Down Expand Up @@ -804,7 +804,7 @@ impl<K: Ord, V> BTreeMap<K, V> {
///
/// ```
/// use std::collections::BTreeMap;
/// use std::collections::Bound::Included;
/// use std::ops::Bound::Included;
///
/// let mut map = BTreeMap::new();
/// map.insert(3, "a");
Expand All @@ -817,7 +817,7 @@ impl<K: Ord, V> BTreeMap<K, V> {
/// ```
#[stable(feature = "btree_range", since = "1.17.0")]
pub fn range<T: ?Sized, R>(&self, range: R) -> Range<K, V>
where T: Ord, K: Borrow<T>, R: RangeArgument<T>
where T: Ord, K: Borrow<T>, R: RangeBounds<T>
{
let root1 = self.root.as_ref();
let root2 = self.root.as_ref();
Expand Down Expand Up @@ -857,7 +857,7 @@ impl<K: Ord, V> BTreeMap<K, V> {
/// ```
#[stable(feature = "btree_range", since = "1.17.0")]
pub fn range_mut<T: ?Sized, R>(&mut self, range: R) -> RangeMut<K, V>
where T: Ord, K: Borrow<T>, R: RangeArgument<T>
where T: Ord, K: Borrow<T>, R: RangeBounds<T>
{
let root1 = self.root.as_mut();
let root2 = unsafe { ptr::read(&root1) };
Expand Down Expand Up @@ -1812,7 +1812,7 @@ fn last_leaf_edge<BorrowType, K, V>
}
}

fn range_search<BorrowType, K, V, Q: ?Sized, R: RangeArgument<Q>>(
fn range_search<BorrowType, K, V, Q: ?Sized, R: RangeBounds<Q>>(
root1: NodeRef<BorrowType, K, V, marker::LeafOrInternal>,
root2: NodeRef<BorrowType, K, V, marker::LeafOrInternal>,
range: R
Expand Down
7 changes: 3 additions & 4 deletions src/liballoc/btree/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,11 @@ use core::cmp::{min, max};
use core::fmt::Debug;
use core::fmt;
use core::iter::{Peekable, FromIterator, FusedIterator};
use core::ops::{BitOr, BitAnd, BitXor, Sub};
use core::ops::{BitOr, BitAnd, BitXor, Sub, RangeBounds};

use borrow::Borrow;
use btree_map::{BTreeMap, Keys};
use super::Recover;
use range::RangeArgument;

// FIXME(conventions): implement bounded iterators

Expand Down Expand Up @@ -240,7 +239,7 @@ impl<T: Ord> BTreeSet<T> {
///
/// ```
/// use std::collections::BTreeSet;
/// use std::collections::Bound::Included;
/// use std::ops::Bound::Included;
///
/// let mut set = BTreeSet::new();
/// set.insert(3);
Expand All @@ -253,7 +252,7 @@ impl<T: Ord> BTreeSet<T> {
/// ```
#[stable(feature = "btree_range", since = "1.17.0")]
pub fn range<K: ?Sized, R>(&self, range: R) -> Range<T>
where K: Ord, T: Borrow<K>, R: RangeArgument<K>
where K: Ord, T: Borrow<K>, R: RangeBounds<K>
{
Range { iter: self.map.range(range) }
}
Expand Down
53 changes: 1 addition & 52 deletions src/liballoc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
#![feature(box_syntax)]
#![feature(cfg_target_has_atomic)]
#![feature(coerce_unsized)]
#![feature(collections_range)]
#![feature(const_fn)]
#![feature(core_intrinsics)]
#![feature(custom_attribute)]
Expand Down Expand Up @@ -178,7 +179,6 @@ mod btree;
pub mod borrow;
pub mod fmt;
pub mod linked_list;
pub mod range;
pub mod slice;
pub mod str;
pub mod string;
Expand All @@ -204,57 +204,6 @@ mod std {
pub use core::ops; // RangeFull
}

/// An endpoint of a range of keys.
///
/// # Examples
///
/// `Bound`s are range endpoints:
///
/// ```
/// #![feature(collections_range)]
///
/// use std::collections::range::RangeArgument;
/// use std::collections::Bound::*;
///
/// assert_eq!((..100).start(), Unbounded);
/// assert_eq!((1..12).start(), Included(&1));
/// assert_eq!((1..12).end(), Excluded(&12));
/// ```
///
/// Using a tuple of `Bound`s as an argument to [`BTreeMap::range`].
/// Note that in most cases, it's better to use range syntax (`1..5`) instead.
///
/// ```
/// use std::collections::BTreeMap;
/// use std::collections::Bound::{Excluded, Included, Unbounded};
///
/// let mut map = BTreeMap::new();
/// map.insert(3, "a");
/// map.insert(5, "b");
/// map.insert(8, "c");
///
/// for (key, value) in map.range((Excluded(3), Included(8))) {
/// println!("{}: {}", key, value);
/// }
///
/// assert_eq!(Some((&3, &"a")), map.range((Unbounded, Included(5))).next());
/// ```
///
/// [`BTreeMap::range`]: btree_map/struct.BTreeMap.html#method.range
#[stable(feature = "collections_bound", since = "1.17.0")]
#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq)]
pub enum Bound<T> {
/// An inclusive bound.
#[stable(feature = "collections_bound", since = "1.17.0")]
Included(#[stable(feature = "collections_bound", since = "1.17.0")] T),
/// An exclusive bound.
#[stable(feature = "collections_bound", since = "1.17.0")]
Excluded(#[stable(feature = "collections_bound", since = "1.17.0")] T),
/// An infinite endpoint. Indicates that there is no bound in this direction.
#[stable(feature = "collections_bound", since = "1.17.0")]
Unbounded,
}

/// An intermediate trait for specialization of `Extend`.
#[doc(hidden)]
trait SpecExtend<I: IntoIterator> {
Expand Down
152 changes: 0 additions & 152 deletions src/liballoc/range.rs

This file was deleted.

9 changes: 4 additions & 5 deletions src/liballoc/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,14 @@
use core::fmt;
use core::hash;
use core::iter::{FromIterator, FusedIterator};
use core::ops::{self, Add, AddAssign, Index, IndexMut};
use core::ops::Bound::{Excluded, Included, Unbounded};
use core::ops::{self, Add, AddAssign, Index, IndexMut, RangeBounds};
use core::ptr;
use core::str::pattern::Pattern;
use std_unicode::lossy;
use std_unicode::char::{decode_utf16, REPLACEMENT_CHARACTER};

use borrow::{Cow, ToOwned};
use range::RangeArgument;
use Bound::{Excluded, Included, Unbounded};
use str::{self, from_boxed_utf8_unchecked, FromStr, Utf8Error, Chars};
use vec::Vec;
use boxed::Box;
Expand Down Expand Up @@ -1484,7 +1483,7 @@ impl String {
/// ```
#[stable(feature = "drain", since = "1.6.0")]
pub fn drain<R>(&mut self, range: R) -> Drain
where R: RangeArgument<usize>
where R: RangeBounds<usize>
{
// Memory safety
//
Expand Down Expand Up @@ -1548,7 +1547,7 @@ impl String {
/// ```
#[unstable(feature = "splice", reason = "recently added", issue = "44643")]
pub fn splice<R>(&mut self, range: R, replace_with: &str)
where R: RangeArgument<usize>
where R: RangeBounds<usize>
{
// Memory safety
//
Expand Down
2 changes: 1 addition & 1 deletion src/liballoc/tests/btree/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
// except according to those terms.

use std::collections::BTreeMap;
use std::collections::Bound::{self, Excluded, Included, Unbounded};
use std::collections::btree_map::Entry::{Occupied, Vacant};
use std::ops::Bound::{self, Excluded, Included, Unbounded};
use std::rc::Rc;

use std::iter::FromIterator;
Expand Down
9 changes: 4 additions & 5 deletions src/liballoc/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ use core::marker::PhantomData;
use core::mem;
#[cfg(not(test))]
use core::num::Float;
use core::ops::{InPlace, Index, IndexMut, Place, Placer};
use core::ops::Bound::{Excluded, Included, Unbounded};
use core::ops::{InPlace, Index, IndexMut, Place, Placer, RangeBounds};
use core::ops;
use core::ptr;
use core::ptr::NonNull;
Expand All @@ -85,9 +86,7 @@ use borrow::ToOwned;
use borrow::Cow;
use boxed::Box;
use raw_vec::RawVec;
use super::range::RangeArgument;
use super::allocator::CollectionAllocErr;
use Bound::{Excluded, Included, Unbounded};

/// A contiguous growable array type, written `Vec<T>` but pronounced 'vector'.
///
Expand Down Expand Up @@ -1176,7 +1175,7 @@ impl<T> Vec<T> {
/// ```
#[stable(feature = "drain", since = "1.6.0")]
pub fn drain<R>(&mut self, range: R) -> Drain<T>
where R: RangeArgument<usize>
where R: RangeBounds<usize>
{
// Memory safety
//
Expand Down Expand Up @@ -1950,7 +1949,7 @@ impl<T> Vec<T> {
#[inline]
#[stable(feature = "vec_splice", since = "1.21.0")]
pub fn splice<R, I>(&mut self, range: R, replace_with: I) -> Splice<I::IntoIter>
where R: RangeArgument<usize>, I: IntoIterator<Item=T>
where R: RangeBounds<usize>, I: IntoIterator<Item=T>
{
Splice {
drain: self.drain(range),
Expand Down
Loading