diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:11:38 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:12:43 +0000 |
commit | cf94bdc0742c13e2a0cac864c478b8626b266e1b (patch) | |
tree | 044670aa50cc5e2b4229aa0b6b3df6676730c0a6 /library/core/src/result.rs | |
parent | Adding debian version 1.65.0+dfsg1-2. (diff) | |
download | rustc-cf94bdc0742c13e2a0cac864c478b8626b266e1b.tar.xz rustc-cf94bdc0742c13e2a0cac864c478b8626b266e1b.zip |
Merging upstream version 1.66.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | library/core/src/result.rs | 34 |
1 files changed, 19 insertions, 15 deletions
diff --git a/library/core/src/result.rs b/library/core/src/result.rs index 76eaa191f..3f33c5fd6 100644 --- a/library/core/src/result.rs +++ b/library/core/src/result.rs @@ -548,22 +548,25 @@ impl<T, E> Result<T, E> { /// # Examples /// /// ``` - /// #![feature(is_some_with)] + /// #![feature(is_some_and)] /// /// 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)) + #[unstable(feature = "is_some_and", issue = "93050")] + 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`]. @@ -592,7 +595,7 @@ impl<T, E> Result<T, E> { /// # Examples /// /// ``` - /// #![feature(is_some_with)] + /// #![feature(is_some_and)] /// use std::io::{Error, ErrorKind}; /// /// let x: Result<u32, Error> = Err(Error::new(ErrorKind::NotFound, "!")); @@ -606,9 +609,12 @@ 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)) + #[unstable(feature = "is_some_and", issue = "93050")] + pub fn is_err_and(self, f: impl FnOnce(E) -> bool) -> bool { + match self { + Ok(_) => false, + Err(e) => f(e), + } } ///////////////////////////////////////////////////////////////////////// @@ -2066,9 +2072,6 @@ impl<A, E, V: FromIterator<A>> FromIterator<Result<A, E>> for Result<V, E> { /// so the final value of `shared` is 6 (= `3 + 2 + 1`), not 16. #[inline] fn from_iter<I: IntoIterator<Item = Result<A, E>>>(iter: I) -> Result<V, E> { - // FIXME(#11084): This could be replaced with Iterator::scan when this - // performance bug is closed. - iter::try_process(iter.into_iter(), |i| i.collect()) } } @@ -2116,6 +2119,7 @@ impl<T, E, F: From<E>> ops::FromResidual<ops::Yeet<E>> for Result<T, F> { } #[unstable(feature = "try_trait_v2_residual", issue = "91285")] -impl<T, E> ops::Residual<T> for Result<convert::Infallible, E> { +#[rustc_const_unstable(feature = "const_try", issue = "74935")] +impl<T, E> const ops::Residual<T> for Result<convert::Infallible, E> { type TryType = Result<T, E>; } |