1#[cfg(not(feature = "ferrocene_certified"))]
4use crate::convert::Infallible;
5#[cfg(not(feature = "ferrocene_certified"))]
6use crate::error::Error;
7#[cfg(not(feature = "ferrocene_certified"))]
8use crate::fmt;
9
10#[stable(feature = "try_from", since = "1.34.0")]
12#[cfg_attr(not(feature = "ferrocene_certified"), derive(Debug, Copy, Clone, PartialEq, Eq))]
13pub struct TryFromIntError(pub(crate) ());
14
15#[stable(feature = "try_from", since = "1.34.0")]
16#[cfg(not(feature = "ferrocene_certified"))]
17impl fmt::Display for TryFromIntError {
18 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
19 "out of range integral type conversion attempted".fmt(f)
20 }
21}
22
23#[stable(feature = "try_from", since = "1.34.0")]
24#[cfg(not(feature = "ferrocene_certified"))]
25impl Error for TryFromIntError {}
26
27#[stable(feature = "try_from", since = "1.34.0")]
28#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
29#[cfg(not(feature = "ferrocene_certified"))]
30impl const From<Infallible> for TryFromIntError {
31 fn from(x: Infallible) -> TryFromIntError {
32 match x {}
33 }
34}
35
36#[unstable(feature = "never_type", issue = "35121")]
37#[rustc_const_unstable(feature = "const_convert", issue = "143773")]
38#[cfg(not(feature = "ferrocene_certified"))]
39impl const From<!> for TryFromIntError {
40 #[inline]
41 fn from(never: !) -> TryFromIntError {
42 match never {}
46 }
47}
48
49#[derive(Debug, Clone, PartialEq, Eq)]
71#[stable(feature = "rust1", since = "1.0.0")]
72#[cfg(not(feature = "ferrocene_certified"))]
73pub struct ParseIntError {
74 pub(super) kind: IntErrorKind,
75}
76
77#[stable(feature = "int_error_matching", since = "1.55.0")]
89#[derive(Debug, Clone, PartialEq, Eq, Copy, Hash)]
90#[non_exhaustive]
91#[cfg(not(feature = "ferrocene_certified"))]
92pub enum IntErrorKind {
93 #[stable(feature = "int_error_matching", since = "1.55.0")]
97 Empty,
98 #[stable(feature = "int_error_matching", since = "1.55.0")]
106 InvalidDigit,
107 #[stable(feature = "int_error_matching", since = "1.55.0")]
109 PosOverflow,
110 #[stable(feature = "int_error_matching", since = "1.55.0")]
112 NegOverflow,
113 #[stable(feature = "int_error_matching", since = "1.55.0")]
118 Zero,
119}
120
121#[cfg(not(feature = "ferrocene_certified"))]
122impl ParseIntError {
123 #[must_use]
125 #[rustc_const_stable(feature = "const_int_from_str", since = "1.82.0")]
126 #[stable(feature = "int_error_matching", since = "1.55.0")]
127 pub const fn kind(&self) -> &IntErrorKind {
128 &self.kind
129 }
130}
131
132#[stable(feature = "rust1", since = "1.0.0")]
133#[cfg(not(feature = "ferrocene_certified"))]
134impl fmt::Display for ParseIntError {
135 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
136 match self.kind {
137 IntErrorKind::Empty => "cannot parse integer from empty string",
138 IntErrorKind::InvalidDigit => "invalid digit found in string",
139 IntErrorKind::PosOverflow => "number too large to fit in target type",
140 IntErrorKind::NegOverflow => "number too small to fit in target type",
141 IntErrorKind::Zero => "number would be zero for non-zero type",
142 }
143 .fmt(f)
144 }
145}
146
147#[stable(feature = "rust1", since = "1.0.0")]
148#[cfg(not(feature = "ferrocene_certified"))]
149impl Error for ParseIntError {}