summary refs log tree commit diff
path: root/src/libcore/tests
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2017-09-29 22:35:23 +0000
committerbors <bors@rust-lang.org>2017-09-29 22:35:23 +0000
commitb7041bfab3a83702a8026fb7a18d8ea7d54cc648 (patch)
tree7f22fe35983186a4d48ea90d70c6461d11ef1269 /src/libcore/tests
parent6f87d20a7cce70b8cc59a1adf3037d14bc83f237 (diff)
parent27d95d3645761252caf42c77fc53b76b4278520a (diff)
downloadrust-b7041bfab3a83702a8026fb7a18d8ea7d54cc648.tar.gz
rust-b7041bfab3a83702a8026fb7a18d8ea7d54cc648.zip
Auto merge of #44174 - jimmycuadra:try-from-infallible, r=sfackler
Add blanket TryFrom impl when From is implemented.

Adds `impl<T, U> TryFrom<T> for U where U: From<T>`.

Removes `impl<'a, T> TryFrom<&'a str> for T where T: FromStr` (originally added in #40281) due to overlapping impls caused by the new blanket impl. This removal is to be discussed further on the tracking issue for TryFrom.

Refs #33417.

/cc @sfackler, @scottmcm (thank you for the help!), and @aturon
Diffstat (limited to 'src/libcore/tests')
-rw-r--r--src/libcore/tests/char.rs1
-rw-r--r--src/libcore/tests/num/mod.rs10
2 files changed, 9 insertions, 2 deletions
diff --git a/src/libcore/tests/char.rs b/src/libcore/tests/char.rs
index 7c3b90c8153..4e10ceac878 100644
--- a/src/libcore/tests/char.rs
+++ b/src/libcore/tests/char.rs
@@ -32,7 +32,6 @@ fn test_convert() {
 #[test]
 fn test_from_str() {
     assert_eq!(char::from_str("a").unwrap(), 'a');
-    assert_eq!(char::try_from("a").unwrap(), 'a');
     assert_eq!(char::from_str("\0").unwrap(), '\0');
     assert_eq!(char::from_str("\u{D7FF}").unwrap(), '\u{d7FF}');
     assert!(char::from_str("").is_err());
diff --git a/src/libcore/tests/num/mod.rs b/src/libcore/tests/num/mod.rs
index 400d53ce51a..7eb5ff98857 100644
--- a/src/libcore/tests/num/mod.rs
+++ b/src/libcore/tests/num/mod.rs
@@ -8,10 +8,11 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-use core::convert::TryFrom;
+use core::convert::{TryFrom, TryInto};
 use core::cmp::PartialEq;
 use core::fmt::Debug;
 use core::marker::Copy;
+use core::num::TryFromIntError;
 use core::ops::{Add, Sub, Mul, Div, Rem};
 use core::option::Option;
 use core::option::Option::{Some, None};
@@ -134,6 +135,13 @@ fn test_empty() {
     assert_eq!("".parse::<u8>().ok(), None);
 }
 
+#[test]
+fn test_infallible_try_from_int_error() {
+    let func = |x: i8| -> Result<i32, TryFromIntError> { Ok(x.try_into()?) };
+
+    assert!(func(0).is_ok());
+}
+
 macro_rules! test_impl_from {
     ($fn_name: ident, $Small: ty, $Large: ty) => {
         #[test]