Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Rename Result::unwrap_infallible to into_ok
  • Loading branch information
mzabaluev committed Dec 22, 2019
commit 6f0672c08b7609c7ed77245a3feea3040221b804
4 changes: 2 additions & 2 deletions src/libcore/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1109,11 +1109,11 @@ impl<T, E: Into<!>> Result<T, E> {
/// Ok("this is fine".into())
/// }
///
/// let s: String = only_good_news().unwrap_infallible();
/// let s: String = only_good_news().into_ok();
/// println!("{}", s);
/// ```
#[inline]
pub fn unwrap_infallible(self) -> T {
pub fn into_ok(self) -> T {
match self {
Ok(x) => x,
Err(e) => e.into(),
Expand Down
6 changes: 3 additions & 3 deletions src/libcore/tests/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,12 +198,12 @@ pub fn test_unwrap_or_default() {
}

#[test]
pub fn test_unwrap_infallible() {
pub fn test_into_ok() {
fn infallible_op() -> Result<isize, !> {
Ok(666)
}

assert_eq!(infallible_op().unwrap_infallible(), 666);
assert_eq!(infallible_op().into_ok(), 666);

enum MyNeverToken {}
impl From<MyNeverToken> for ! {
Expand All @@ -216,7 +216,7 @@ pub fn test_unwrap_infallible() {
Ok(667)
}

assert_eq!(infallible_op2().unwrap_infallible(), 667);
assert_eq!(infallible_op2().into_ok(), 667);
}

#[test]
Expand Down