Skip to content

Commit

Permalink
libcore: test Result::unwrap_infallible
Browse files Browse the repository at this point in the history
  • Loading branch information
mzabaluev committed Dec 22, 2019
1 parent a20013b commit 9a99a21
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/libcore/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
#![feature(slice_from_raw_parts)]
#![feature(const_slice_from_raw_parts)]
#![feature(const_raw_ptr_deref)]
#![feature(never_type)]
#![feature(unwrap_infallible)]

extern crate test;

Expand Down
22 changes: 22 additions & 0 deletions src/libcore/tests/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,28 @@ pub fn test_unwrap_or_default() {
assert_eq!(op2().unwrap_or_default(), 0);
}

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

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

enum MyNeverToken {}
impl From<MyNeverToken> for ! {
fn from(never: MyNeverToken) -> ! {
match never {}
}
}

fn infallible_op2() -> Result<isize, MyNeverToken> {
Ok(667)
}

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

#[test]
fn test_try() {
fn try_result_some() -> Option<u8> {
Expand Down

0 comments on commit 9a99a21

Please sign in to comment.