X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;ds=sidebyside;f=library%2Fcore%2Fsrc%2Foption.rs;h=4b57371096e9ab670f3c99e35e8220a47600c972;hb=d10b47ef69a36590a04c76e8868093d251adfec6;hp=4a93df4591b7a6b70681f7f8094b68e377e18e60;hpb=8a497b7181cad4ae66dbd6cc31042b69b6bd0df7;p=rust.git diff --git a/library/core/src/option.rs b/library/core/src/option.rs index 4a93df4591b..4b57371096e 100644 --- a/library/core/src/option.rs +++ b/library/core/src/option.rs @@ -559,22 +559,25 @@ pub const fn is_some(&self) -> bool { /// # Examples /// /// ``` - /// #![feature(is_some_with)] + /// #![feature(is_some_and)] /// /// 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)) + #[unstable(feature = "is_some_and", issue = "93050")] + 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.