diff --git a/library/core/src/num/error.rs b/library/core/src/num/error.rs index 8cd065630cd88..3565d9a51fa34 100644 --- a/library/core/src/num/error.rs +++ b/library/core/src/num/error.rs @@ -21,7 +21,14 @@ impl TryFromIntError { #[stable(feature = "try_from", since = "1.34.0")] impl fmt::Display for TryFromIntError { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - "out of range integral type conversion attempted".fmt(f) + match self.0 { + IntErrorKind::Empty | IntErrorKind::InvalidDigit => unreachable!(), + IntErrorKind::PosOverflow => "number too large to fit in target type", + IntErrorKind::NegOverflow => "number too small to fit in target type", + IntErrorKind::Zero => "number would be zero for non-zero type", + IntErrorKind::NotAPowerOfTwo => "number is not a power of two", + } + .fmt(f) } }