diff options
| author | bors <bors@rust-lang.org> | 2019-06-06 20:46:15 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2019-06-06 20:46:15 +0000 |
| commit | 5eeb567a27eba18420a620ca7d0c007e29d8bc0c (patch) | |
| tree | e2e372e69972bcb438f6fc9951d4b05831190bf9 /src/libcore | |
| parent | 8b36867093fb774bcbd9f787cbc470a5f44c1310 (diff) | |
| parent | 9e97970fe240df0b9a6e65055e670f40f02e416d (diff) | |
| download | rust-5eeb567a27eba18420a620ca7d0c007e29d8bc0c.tar.gz rust-5eeb567a27eba18420a620ca7d0c007e29d8bc0c.zip | |
Auto merge of #61601 - Centril:rollup-uegbsns, r=Centril
Rollup of 5 pull requests Successful merges: - #61376 (Add Bound::cloned()) - #61554 (Change visit api) - #61559 (Make visitors iterate) - #61585 (Update .mailmap with my name) - #61591 (Update .mailmap) Failed merges: r? @ghost
Diffstat (limited to 'src/libcore')
| -rw-r--r-- | src/libcore/lib.rs | 1 | ||||
| -rw-r--r-- | src/libcore/ops/range.rs | 23 | ||||
| -rw-r--r-- | src/libcore/tests/lib.rs | 1 | ||||
| -rw-r--r-- | src/libcore/tests/ops.rs | 17 |
4 files changed, 41 insertions, 1 deletions
diff --git a/src/libcore/lib.rs b/src/libcore/lib.rs index ad352048047..af24cbe1c5c 100644 --- a/src/libcore/lib.rs +++ b/src/libcore/lib.rs @@ -70,6 +70,7 @@ #![feature(arbitrary_self_types)] #![feature(asm)] #![feature(associated_type_defaults)] +#![feature(bound_cloned)] #![feature(cfg_target_has_atomic)] #![feature(concat_idents)] #![feature(const_fn)] diff --git a/src/libcore/ops/range.rs b/src/libcore/ops/range.rs index a707f0cc062..1b4c4218cc1 100644 --- a/src/libcore/ops/range.rs +++ b/src/libcore/ops/range.rs @@ -696,6 +696,29 @@ pub enum Bound<T> { Unbounded, } +impl<T: Clone> Bound<&T> { + /// Map a `Bound<&T>` to a `Bound<T>` by cloning the contents of the bound. + /// + /// # Examples + /// + /// ``` + /// #![feature(bound_cloned)] + /// use std::ops::Bound::*; + /// use std::ops::RangeBounds; + /// + /// assert_eq!((1..12).start_bound(), Included(&1)); + /// assert_eq!((1..12).start_bound().cloned(), Included(1)); + /// ``` + #[unstable(feature = "bound_cloned", issue = "61356")] + pub fn cloned(self) -> Bound<T> { + match self { + Bound::Unbounded => Bound::Unbounded, + Bound::Included(x) => Bound::Included(x.clone()), + Bound::Excluded(x) => Bound::Excluded(x.clone()), + } + } +} + #[stable(feature = "collections_range", since = "1.28.0")] /// `RangeBounds` is implemented by Rust's built-in range types, produced /// by range syntax like `..`, `a..`, `..b`, `..=c`, `d..e`, or `f..=g`. diff --git a/src/libcore/tests/lib.rs b/src/libcore/tests/lib.rs index 5050842e409..928bdd7a760 100644 --- a/src/libcore/tests/lib.rs +++ b/src/libcore/tests/lib.rs @@ -1,3 +1,4 @@ +#![feature(bound_cloned)] #![feature(box_syntax)] #![feature(cell_update)] #![feature(core_private_bignum)] diff --git a/src/libcore/tests/ops.rs b/src/libcore/tests/ops.rs index 78cf07119e7..48755ae4c16 100644 --- a/src/libcore/tests/ops.rs +++ b/src/libcore/tests/ops.rs @@ -1,4 +1,4 @@ -use core::ops::{Range, RangeFull, RangeFrom, RangeTo, RangeInclusive}; +use core::ops::{Bound, Range, RangeFull, RangeFrom, RangeTo, RangeInclusive}; // Test the Range structs without the syntactic sugar. @@ -82,3 +82,18 @@ fn test_range_is_empty() { assert!( (NAN ..= EPSILON).is_empty()); assert!( (NAN ..= NAN).is_empty()); } + +#[test] +fn test_bound_cloned_unbounded() { + assert_eq!(Bound::<&u32>::Unbounded.cloned(), Bound::Unbounded); +} + +#[test] +fn test_bound_cloned_included() { + assert_eq!(Bound::Included(&3).cloned(), Bound::Included(3)); +} + +#[test] +fn test_bound_cloned_excluded() { + assert_eq!(Bound::Excluded(&3).cloned(), Bound::Excluded(3)); +} |
