diff options
| author | Cameron Steffen <cam.steffen94@gmail.com> | 2022-06-21 14:27:53 -0500 |
|---|---|---|
| committer | Cameron Steffen <cam.steffen94@gmail.com> | 2022-10-01 11:45:52 -0500 |
| commit | 2f83134e375a98b14ecb2b10dbea0c8b2c43f5ed (patch) | |
| tree | a25a24fe436f1a07b1cc003aff2cf066431c8e11 | |
| parent | 744e397d8855f7da87d70aa8d0bd9e0f5f0b51a1 (diff) | |
| download | rust-2f83134e375a98b14ecb2b10dbea0c8b2c43f5ed.tar.gz rust-2f83134e375a98b14ecb2b10dbea0c8b2c43f5ed.zip | |
Change is_some_and to take by value
| -rw-r--r-- | library/core/src/option.rs | 13 | ||||
| -rw-r--r-- | library/core/src/result.rs | 20 | ||||
| -rw-r--r-- | src/tools/miri/src/stacked_borrows/stack.rs | 2 |
3 files changed, 22 insertions, 13 deletions
diff --git a/library/core/src/option.rs b/library/core/src/option.rs index 4a93df4591b..0623d304004 100644 --- a/library/core/src/option.rs +++ b/library/core/src/option.rs @@ -562,19 +562,22 @@ impl<T> Option<T> { /// #![feature(is_some_with)] /// /// let x: Option<u32> = Some(2); - /// assert_eq!(x.is_some_and(|&x| x > 1), true); + /// assert_eq!(x.is_some_and(|x| x > 1), true); /// /// let x: Option<u32> = Some(0); - /// assert_eq!(x.is_some_and(|&x| x > 1), false); + /// assert_eq!(x.is_some_and(|x| x > 1), false); /// /// let x: Option<u32> = None; - /// assert_eq!(x.is_some_and(|&x| x > 1), false); + /// assert_eq!(x.is_some_and(|x| x > 1), false); /// ``` #[must_use] #[inline] #[unstable(feature = "is_some_with", issue = "93050")] - pub fn is_some_and(&self, f: impl FnOnce(&T) -> bool) -> bool { - matches!(self, Some(x) if f(x)) + pub fn is_some_and(self, f: impl FnOnce(T) -> bool) -> bool { + match self { + None => false, + Some(x) => f(x), + } } /// Returns `true` if the option is a [`None`] value. diff --git a/library/core/src/result.rs b/library/core/src/result.rs index dc90e90402c..7c740bbd01f 100644 --- a/library/core/src/result.rs +++ b/library/core/src/result.rs @@ -551,19 +551,22 @@ impl<T, E> Result<T, E> { /// #![feature(is_some_with)] /// /// let x: Result<u32, &str> = Ok(2); - /// assert_eq!(x.is_ok_and(|&x| x > 1), true); + /// assert_eq!(x.is_ok_and(|x| x > 1), true); /// /// let x: Result<u32, &str> = Ok(0); - /// assert_eq!(x.is_ok_and(|&x| x > 1), false); + /// assert_eq!(x.is_ok_and(|x| x > 1), false); /// /// let x: Result<u32, &str> = Err("hey"); - /// assert_eq!(x.is_ok_and(|&x| x > 1), false); + /// assert_eq!(x.is_ok_and(|x| x > 1), false); /// ``` #[must_use] #[inline] #[unstable(feature = "is_some_with", issue = "93050")] - pub fn is_ok_and(&self, f: impl FnOnce(&T) -> bool) -> bool { - matches!(self, Ok(x) if f(x)) + pub fn is_ok_and(self, f: impl FnOnce(T) -> bool) -> bool { + match self { + Err(_) => false, + Ok(x) => f(x), + } } /// Returns `true` if the result is [`Err`]. @@ -607,8 +610,11 @@ impl<T, E> Result<T, E> { #[must_use] #[inline] #[unstable(feature = "is_some_with", issue = "93050")] - pub fn is_err_and(&self, f: impl FnOnce(&E) -> bool) -> bool { - matches!(self, Err(x) if f(x)) + pub fn is_err_and(self, f: impl FnOnce(E) -> bool) -> bool { + match self { + Ok(_) => false, + Err(e) => f(e), + } } ///////////////////////////////////////////////////////////////////////// diff --git a/src/tools/miri/src/stacked_borrows/stack.rs b/src/tools/miri/src/stacked_borrows/stack.rs index 494ea08b56e..97632af785d 100644 --- a/src/tools/miri/src/stacked_borrows/stack.rs +++ b/src/tools/miri/src/stacked_borrows/stack.rs @@ -211,7 +211,7 @@ impl<'tcx> Stack { } // Couldn't find it in the stack; but if there is an unknown bottom it might be there. - let found = self.unknown_bottom.is_some_and(|&unknown_limit| { + let found = self.unknown_bottom.is_some_and(|unknown_limit| { tag.0 < unknown_limit.0 // unknown_limit is an upper bound for what can be in the unknown bottom. }); if found { Ok(None) } else { Err(()) } |
