From 2f83134e375a98b14ecb2b10dbea0c8b2c43f5ed Mon Sep 17 00:00:00 2001 From: Cameron Steffen Date: Tue, 21 Jun 2022 14:27:53 -0500 Subject: [PATCH] Change is_some_and to take by value --- library/core/src/option.rs | 13 ++++++++----- library/core/src/result.rs | 20 +++++++++++++------- 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 Option { /// #![feature(is_some_with)] /// /// let x: Option = 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 = 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 = 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 Result { /// #![feature(is_some_with)] /// /// let x: Result = 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 = 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 = 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 Result { #[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(()) }