diff options
| author | bors <bors@rust-lang.org> | 2025-09-01 04:37:39 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2025-09-01 04:37:39 +0000 |
| commit | be4e9b77ab5502b7beda0b787fb3c978a7b4db79 (patch) | |
| tree | dd1d9cf867518d0207b9d269a940ef67201eeebc /library/core/src | |
| parent | 828e45ad11ce4ab56dd64e93f1fb5dd8f0c0ae93 (diff) | |
| parent | 0dbd8e68b129ca35df99eae7bc824f26d5098336 (diff) | |
| download | rust-be4e9b77ab5502b7beda0b787fb3c978a7b4db79.tar.gz rust-be4e9b77ab5502b7beda0b787fb3c978a7b4db79.zip | |
Auto merge of #146072 - Zalathar:rollup-0svnrfe, r=Zalathar
Rollup of 6 pull requests Successful merges: - rust-lang/rust#145421 (`dump_mir` cleanups) - rust-lang/rust#145968 (Add `Bound::copied`) - rust-lang/rust#146004 (resolve: Refactor `struct ExternPreludeEntry`) - rust-lang/rust#146042 (Detect negative literal inferred to unsigned integer) - rust-lang/rust#146046 (Suggest method name with maybe ty mismatch) - rust-lang/rust#146051 (Change std f32 test to pass under Miri) r? `@ghost` `@rustbot` modify labels: rollup
Diffstat (limited to 'library/core/src')
| -rw-r--r-- | library/core/src/ops/range.rs | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/library/core/src/ops/range.rs b/library/core/src/ops/range.rs index 95d1e2069ac..c0a27775694 100644 --- a/library/core/src/ops/range.rs +++ b/library/core/src/ops/range.rs @@ -736,6 +736,31 @@ impl<T> Bound<T> { } } +impl<T: Copy> Bound<&T> { + /// Map a `Bound<&T>` to a `Bound<T>` by copying the contents of the bound. + /// + /// # Examples + /// + /// ``` + /// #![feature(bound_copied)] + /// + /// use std::ops::Bound::*; + /// use std::ops::RangeBounds; + /// + /// assert_eq!((1..12).start_bound(), Included(&1)); + /// assert_eq!((1..12).start_bound().copied(), Included(1)); + /// ``` + #[unstable(feature = "bound_copied", issue = "145966")] + #[must_use] + pub fn copied(self) -> Bound<T> { + match self { + Bound::Unbounded => Bound::Unbounded, + Bound::Included(x) => Bound::Included(*x), + Bound::Excluded(x) => Bound::Excluded(*x), + } + } +} + impl<T: Clone> Bound<&T> { /// Map a `Bound<&T>` to a `Bound<T>` by cloning the contents of the bound. /// @@ -745,8 +770,11 @@ impl<T: Clone> Bound<&T> { /// 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)); + /// let a1 = String::from("a"); + /// let (a2, a3, a4) = (a1.clone(), a1.clone(), a1.clone()); + /// + /// assert_eq!(Included(&a1), (a2..).start_bound()); + /// assert_eq!(Included(a3), (a4..).start_bound().cloned()); /// ``` #[must_use = "`self` will be dropped if the result is not used"] #[stable(feature = "bound_cloned", since = "1.55.0")] |
