diff options
| author | Jacob Pratt <jacob@jhpratt.dev> | 2021-02-14 22:11:46 -0500 |
|---|---|---|
| committer | Jacob Pratt <jacob@jhpratt.dev> | 2021-03-06 14:17:49 -0500 |
| commit | 79c2b75e88bdab5fccd7d63750ef11aff2f8eaba (patch) | |
| tree | f1b99e98f30f9ecfc655911a22ed8c8fc88f09be | |
| parent | 097bc6a84f2280a889b9ab4b544f27851a978927 (diff) | |
| download | rust-79c2b75e88bdab5fccd7d63750ef11aff2f8eaba.tar.gz rust-79c2b75e88bdab5fccd7d63750ef11aff2f8eaba.zip | |
Make some Option, Result methods unstably const
The following functions are now unstably const: - Option::transpose - Option::flatten - Result::transpose
| -rw-r--r-- | library/core/src/option.rs | 13 | ||||
| -rw-r--r-- | library/core/src/result.rs | 3 |
2 files changed, 11 insertions, 5 deletions
diff --git a/library/core/src/option.rs b/library/core/src/option.rs index 14e4e4da3b9..c5c7922f819 100644 --- a/library/core/src/option.rs +++ b/library/core/src/option.rs @@ -150,7 +150,7 @@ use crate::iter::{FromIterator, FusedIterator, TrustedLen}; use crate::pin::Pin; use crate::{ - convert, fmt, hint, mem, + fmt, hint, mem, ops::{self, Deref, DerefMut}, }; @@ -1275,7 +1275,8 @@ impl<T, E> Option<Result<T, E>> { /// ``` #[inline] #[stable(feature = "transpose_result", since = "1.33.0")] - pub fn transpose(self) -> Result<Option<T>, E> { + #[rustc_const_unstable(feature = "const_option", issue = "67441")] + pub const fn transpose(self) -> Result<Option<T>, E> { match self { Some(Ok(x)) => Ok(Some(x)), Some(Err(e)) => Err(e), @@ -1750,7 +1751,11 @@ impl<T> Option<Option<T>> { /// ``` #[inline] #[stable(feature = "option_flattening", since = "1.40.0")] - pub fn flatten(self) -> Option<T> { - self.and_then(convert::identity) + #[rustc_const_unstable(feature = "const_option", issue = "67441")] + pub const fn flatten(self) -> Option<T> { + match self { + Some(inner) => inner, + None => None, + } } } diff --git a/library/core/src/result.rs b/library/core/src/result.rs index a43ba5882ed..a00cd98ae5c 100644 --- a/library/core/src/result.rs +++ b/library/core/src/result.rs @@ -1233,7 +1233,8 @@ impl<T, E> Result<Option<T>, E> { /// ``` #[inline] #[stable(feature = "transpose_result", since = "1.33.0")] - pub fn transpose(self) -> Option<Result<T, E>> { + #[rustc_const_unstable(feature = "const_result", issue = "82814")] + pub const fn transpose(self) -> Option<Result<T, E>> { match self { Ok(Some(x)) => Some(Ok(x)), Ok(None) => None, |
