Skip to content

Commit

Permalink
Rollup merge of #100604 - dtolnay:okorerr, r=m-ou-se
Browse files Browse the repository at this point in the history
Remove unstable Result::into_ok_or_err

Pending FCP: rust-lang/rust#82223 (comment)

```@rustbot``` label +waiting-on-fcp
  • Loading branch information
JohnTitor authored Aug 26, 2022
2 parents aadfec1 + 3914ccd commit 31bd061
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 44 deletions.
34 changes: 0 additions & 34 deletions core/src/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1776,40 +1776,6 @@ impl<T, E> Result<Result<T, E>, E> {
}
}

impl<T> Result<T, T> {
/// Returns the [`Ok`] value if `self` is `Ok`, and the [`Err`] value if
/// `self` is `Err`.
///
/// In other words, this function returns the value (the `T`) of a
/// `Result<T, T>`, regardless of whether or not that result is `Ok` or
/// `Err`.
///
/// This can be useful in conjunction with APIs such as
/// [`Atomic*::compare_exchange`], or [`slice::binary_search`], but only in
/// cases where you don't care if the result was `Ok` or not.
///
/// [`Atomic*::compare_exchange`]: crate::sync::atomic::AtomicBool::compare_exchange
///
/// # Examples
///
/// ```
/// #![feature(result_into_ok_or_err)]
/// let ok: Result<u32, u32> = Ok(3);
/// let err: Result<u32, u32> = Err(4);
///
/// assert_eq!(ok.into_ok_or_err(), 3);
/// assert_eq!(err.into_ok_or_err(), 4);
/// ```
#[inline]
#[unstable(feature = "result_into_ok_or_err", reason = "newly added", issue = "82223")]
pub const fn into_ok_or_err(self) -> T {
match self {
Ok(v) => v,
Err(v) => v,
}
}
}

// This is a separate function to reduce the code size of the methods
#[cfg(not(feature = "panic_immediate_abort"))]
#[inline(never)]
Expand Down
1 change: 0 additions & 1 deletion core/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@
#![feature(const_pin)]
#![feature(never_type)]
#![feature(unwrap_infallible)]
#![feature(result_into_ok_or_err)]
#![feature(pointer_byte_offsets)]
#![feature(portable_simd)]
#![feature(ptr_metadata)]
Expand Down
9 changes: 0 additions & 9 deletions core/tests/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,6 @@ fn test_unwrap_or() {
assert_eq!(ok_err.unwrap_or(50), 50);
}

#[test]
fn test_ok_or_err() {
let ok: Result<isize, isize> = Ok(100);
let err: Result<isize, isize> = Err(200);

assert_eq!(ok.into_ok_or_err(), 100);
assert_eq!(err.into_ok_or_err(), 200);
}

#[test]
fn test_unwrap_or_else() {
fn handler(msg: &'static str) -> isize {
Expand Down

0 comments on commit 31bd061

Please sign in to comment.