From 13ca58083dafe75ca6deb491bc38fe3479fe51aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Linus=20F=C3=A4rnstrand?= Date: Thu, 25 Mar 2021 08:50:10 +0100 Subject: [PATCH 1/2] Implement Into for Infallible --- library/core/src/convert/mod.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/library/core/src/convert/mod.rs b/library/core/src/convert/mod.rs index 65af8508a6839..1eaf5cf07d835 100644 --- a/library/core/src/convert/mod.rs +++ b/library/core/src/convert/mod.rs @@ -728,6 +728,13 @@ impl From for Infallible { } } +#[stable(feature = "convert_into_infallible", since = "1.53.0")] +impl Into for Infallible { + fn into(self) -> ! { + match self {} + } +} + #[stable(feature = "convert_infallible_hash", since = "1.44.0")] impl Hash for Infallible { fn hash(&self, _: &mut H) { From 0a8fa2ab6c271fca754abb8de2187eae1dc03040 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Linus=20F=C3=A4rnstrand?= Date: Thu, 25 Mar 2021 21:17:38 +0100 Subject: [PATCH 2/2] Add tests --- library/core/tests/result.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/library/core/tests/result.rs b/library/core/tests/result.rs index c461ab380ad3d..f66ea26b62e01 100644 --- a/library/core/tests/result.rs +++ b/library/core/tests/result.rs @@ -1,3 +1,4 @@ +use core::convert::Infallible; use core::ops::DerefMut; use core::option::*; @@ -208,8 +209,12 @@ pub fn test_into_ok() { fn infallible_op() -> Result { Ok(666) } + fn infallible_op_enum() -> Result { + Ok(666) + } assert_eq!(infallible_op().into_ok(), 666); + assert_eq!(infallible_op_enum().into_ok(), 666); enum MyNeverToken {} impl From for ! { @@ -230,8 +235,12 @@ pub fn test_into_err() { fn until_error_op() -> Result { Err(666) } + fn until_error_op_enum() -> Result { + Err(666) + } assert_eq!(until_error_op().into_err(), 666); + assert_eq!(until_error_op_enum().into_err(), 666); enum MyNeverToken {} impl From for ! {