Rollup merge of #130692 - RalfJung:result-flatten, r=Noratrieb · qinheping/verify-rust-std@b3d4fde (original) (raw)
2 files changed
lines changed
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -2538,6 +2538,7 @@ impl Option<Option> { | ||
2538 | 2538 | #[stable(feature = "option_flattening", since = "1.40.0")] |
2539 | 2539 | #[rustc_const_unstable(feature = "const_option", issue = "67441")] |
2540 | 2540 | pub const fn flatten(self) -> Option<T> { |
2541 | +// FIXME(const-hack): could be written with `and_then` | |
2541 | 2542 | match self { |
2542 | 2543 | Some(inner) => inner, |
2543 | 2544 | None => None, |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1676,8 +1676,13 @@ impl<T, E> Result<Result<T, E>, E> { | ||
1676 | 1676 | /// ``` |
1677 | 1677 | #[inline] |
1678 | 1678 | #[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 | +} | |
1681 | 1686 | } |
1682 | 1687 | } |
1683 | 1688 |