]> git.lizzy.rs Git - rust.git/commitdiff
libcore: test Result::unwrap_infallible
authorMikhail Zabaluev <mikhail.zabaluev@gmail.com>
Sat, 2 Nov 2019 20:12:51 +0000 (22:12 +0200)
committerMikhail Zabaluev <mikhail.zabaluev@gmail.com>
Sun, 22 Dec 2019 06:35:10 +0000 (08:35 +0200)
src/libcore/tests/lib.rs
src/libcore/tests/result.rs

index 1f20ebc01e9937d62f26fb38a51f21701b2467ba..465602424180453c8cb89772cde11e381d69d8d7 100644 (file)
@@ -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;
 
index 163f8d0ab3797e731d4b51ea58fc0cee4050fbcf..8d17790af562052a172b7b41be2a30b4b9afd258 100644 (file)
@@ -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> {