diff --git a/src/libcore/num/mod.rs b/src/libcore/num/mod.rs index c164e893b4fbf..d73ec11d2e5d6 100644 --- a/src/libcore/num/mod.rs +++ b/src/libcore/num/mod.rs @@ -5,6 +5,7 @@ #![stable(feature = "rust1", since = "1.0.0")] use crate::convert::Infallible; +use crate::convert::TryFrom; use crate::fmt; use crate::intrinsics; use crate::mem; @@ -111,6 +112,14 @@ assert_eq!(size_of::>(), size_of::<", s } } + #[stable(feature = "try_from", since = "1.34.0")] + impl TryFrom<$Int> for $Ty { + type Error = TryFromIntError; + fn try_from(n: $Int) -> Result { + Self::new(n).ok_or(TryFromIntError(())) + } + } + #[stable(feature = "nonzero_bitor", since = "1.45.0")] impl BitOr for $Ty { type Output = Self;