mirror of
https://github.com/rust-lang/rust.git
synced 2024-10-30 05:51:58 +00:00
make unstable Result::flatten a const fn
This commit is contained in:
parent
6ce376774c
commit
89c3cbafb8
@ -2538,6 +2538,7 @@ impl<T> Option<Option<T>> {
|
||||
#[stable(feature = "option_flattening", since = "1.40.0")]
|
||||
#[rustc_const_unstable(feature = "const_option", issue = "67441")]
|
||||
pub const fn flatten(self) -> Option<T> {
|
||||
// FIXME(const-hack): could be written with `and_then`
|
||||
match self {
|
||||
Some(inner) => inner,
|
||||
None => None,
|
||||
|
@ -1676,8 +1676,13 @@ impl<T, E> Result<Result<T, E>, E> {
|
||||
/// ```
|
||||
#[inline]
|
||||
#[unstable(feature = "result_flattening", issue = "70142")]
|
||||
pub fn flatten(self) -> Result<T, E> {
|
||||
self.and_then(convert::identity)
|
||||
#[rustc_const_unstable(feature = "result_flattening", issue = "70142")]
|
||||
pub const fn flatten(self) -> Result<T, E> {
|
||||
// FIXME(const-hack): could be written with `and_then`
|
||||
match self {
|
||||
Ok(inner) => inner,
|
||||
Err(e) => Err(e),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user