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

Refactor core::ops, move RangeArgument to libcore::ops #42269

Closed
wants to merge 7 commits into from
Closed
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
3 changes: 1 addition & 2 deletions src/libcollections/btree/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@ use core::fmt::Debug;
use core::hash::{Hash, Hasher};
use core::iter::{FromIterator, Peekable, FusedIterator};
use core::marker::PhantomData;
use core::ops::Index;
use core::ops::{Index, RangeArgument};
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
3 changes: 1 addition & 2 deletions src/libcollections/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, RangeArgument};

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

// FIXME(conventions): implement bounded iterators

Expand Down
53 changes: 2 additions & 51 deletions src/libcollections/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,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 @@ -129,59 +128,11 @@ pub mod btree_set {

#[cfg(not(test))]
mod std {
pub use core::ops; // RangeFull
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(T),
/// An exclusive bound.
#[stable(feature = "collections_bound", since = "1.17.0")]
Excluded(T),
/// An infinite endpoint. Indicates that there is no bound in this direction.
#[stable(feature = "collections_bound", since = "1.17.0")]
Unbounded,
}
pub use core::collections::Bound;

/// An intermediate trait for specialization of `Extend`.
#[doc(hidden)]
Expand Down
152 changes: 0 additions & 152 deletions src/libcollections/range.rs

This file was deleted.

3 changes: 1 addition & 2 deletions src/libcollections/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,13 @@ use alloc::str as alloc_str;
use core::fmt;
use core::hash;
use core::iter::{FromIterator, FusedIterator};
use core::ops::{self, Add, AddAssign, Index, IndexMut};
use core::ops::{self, Add, AddAssign, Index, IndexMut, RangeArgument};
use core::ptr;
use core::str as core_str;
use core::str::pattern::Pattern;
use std_unicode::char::{decode_utf16, REPLACEMENT_CHARACTER};

use borrow::{Cow, ToOwned};
use range::RangeArgument;
use Bound::{Excluded, Included, Unbounded};
use str::{self, FromStr, Utf8Error, Chars};
use vec::Vec;
Expand Down
3 changes: 1 addition & 2 deletions src/libcollections/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,11 @@ use core::mem;
#[cfg(not(test))]
use core::num::Float;
use core::ops::{InPlace, Index, IndexMut, Place, Placer};
use core::ops;
use core::ops::{self, RangeArgument};
use core::ptr;
use core::ptr::Shared;
use core::slice;

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

/// A contiguous growable array type, written `Vec<T>` but pronounced 'vector'.
Expand Down
3 changes: 1 addition & 2 deletions src/libcollections/vec_deque.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use core::cmp::Ordering;
use core::fmt;
use core::iter::{repeat, FromIterator, FusedIterator};
use core::mem;
use core::ops::{Index, IndexMut, Place, Placer, InPlace};
use core::ops::{Index, IndexMut, Place, Placer, InPlace, RangeArgument};
use core::ptr;
use core::ptr::Shared;
use core::slice;
Expand All @@ -31,7 +31,6 @@ use core::cmp;

use alloc::raw_vec::RawVec;

use super::range::RangeArgument;
use Bound::{Excluded, Included, Unbounded};
use super::vec::Vec;

Expand Down
55 changes: 55 additions & 0 deletions src/libcore/collections.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
//! Collection types.
//!
//! See [`std::collections`](../std/collections/index.html) for a detailed
//! discussion of collections in Rust.

/// 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
#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq)]
#[stable(feature = "collections_bound", since = "1.17.0")]
pub enum Bound<T> {
/// An inclusive bound.
#[stable(feature = "collections_bound", since = "1.17.0")]
Included(T),
/// An exclusive bound.
#[stable(feature = "collections_bound", since = "1.17.0")]
Excluded(T),
/// An infinite endpoint. Indicates that there is no bound in this direction.
#[stable(feature = "collections_bound", since = "1.17.0")]
Unbounded,
}
3 changes: 3 additions & 0 deletions src/libcore/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,9 @@ pub mod str;
pub mod hash;
pub mod fmt;

#[unstable(feature = "core_bound", issue = "0")]
pub mod collections;

// note: does not need to be public
mod char_private;
mod iter_private;
Expand Down
Loading