Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 98aba66

Browse files
committedSep 22, 2024
make unstable Result::flatten a const fn
1 parent d098993 commit 98aba66

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed
 

‎core/src/option.rs

+1
Original file line numberDiff line numberDiff line change
@@ -2538,6 +2538,7 @@ impl<T> Option<Option<T>> {
25382538
#[stable(feature = "option_flattening", since = "1.40.0")]
25392539
#[rustc_const_unstable(feature = "const_option", issue = "67441")]
25402540
pub const fn flatten(self) -> Option<T> {
2541+
// FIXME(const-hack): could be written with `and_then`
25412542
match self {
25422543
Some(inner) => inner,
25432544
None => None,

‎core/src/result.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -1676,8 +1676,13 @@ impl<T, E> Result<Result<T, E>, E> {
16761676
/// ```
16771677
#[inline]
16781678
#[unstable(feature = "result_flattening", issue = "70142")]
1679-
pub fn flatten(self) -> Result<T, E> {
1680-
self.and_then(convert::identity)
1679+
#[rustc_const_unstable(feature = "result_flattening", issue = "70142")]
1680+
pub const fn flatten(self) -> Result<T, E> {
1681+
// FIXME(const-hack): could be written with `and_then`
1682+
match self {
1683+
Ok(inner) => inner,
1684+
Err(e) => Err(e),
1685+
}
16811686
}
16821687
}
16831688

0 commit comments

Comments
 (0)
Please sign in to comment.