impl From<Infallible> for TryFromIntError.
This commit is contained in:
@@ -12,7 +12,7 @@
|
|||||||
|
|
||||||
#![stable(feature = "rust1", since = "1.0.0")]
|
#![stable(feature = "rust1", since = "1.0.0")]
|
||||||
|
|
||||||
use convert::TryFrom;
|
use convert::{Infallible, TryFrom};
|
||||||
use fmt;
|
use fmt;
|
||||||
use intrinsics;
|
use intrinsics;
|
||||||
use str::FromStr;
|
use str::FromStr;
|
||||||
@@ -2503,6 +2503,13 @@ impl fmt::Display for TryFromIntError {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[unstable(feature = "try_from", issue = "33417")]
|
||||||
|
impl From<Infallible> for TryFromIntError {
|
||||||
|
fn from(_: Infallible) -> TryFromIntError {
|
||||||
|
TryFromIntError(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// no possible bounds violation
|
// no possible bounds violation
|
||||||
macro_rules! try_from_unbounded {
|
macro_rules! try_from_unbounded {
|
||||||
($source:ty, $($target:ty),*) => {$(
|
($source:ty, $($target:ty),*) => {$(
|
||||||
|
|||||||
@@ -8,10 +8,11 @@
|
|||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
use core::convert::TryFrom;
|
use core::convert::{TryFrom, TryInto};
|
||||||
use core::cmp::PartialEq;
|
use core::cmp::PartialEq;
|
||||||
use core::fmt::Debug;
|
use core::fmt::Debug;
|
||||||
use core::marker::Copy;
|
use core::marker::Copy;
|
||||||
|
use core::num::TryFromIntError;
|
||||||
use core::ops::{Add, Sub, Mul, Div, Rem};
|
use core::ops::{Add, Sub, Mul, Div, Rem};
|
||||||
use core::option::Option;
|
use core::option::Option;
|
||||||
use core::option::Option::{Some, None};
|
use core::option::Option::{Some, None};
|
||||||
@@ -134,6 +135,13 @@ fn test_empty() {
|
|||||||
assert_eq!("".parse::<u8>().ok(), None);
|
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 {
|
macro_rules! test_impl_from {
|
||||||
($fn_name: ident, $Small: ty, $Large: ty) => {
|
($fn_name: ident, $Small: ty, $Large: ty) => {
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
Reference in New Issue
Block a user