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#[cfg_attr(not(feature = "ferrocene_certified"), derive(Debug, Clone, PartialEq, Eq))]
71#[stable(feature = "rust1", since = "1.0.0")]
72pub struct ParseIntError {
73 #[cfg_attr(feature = "ferrocene_certified", expect(dead_code))]
74 pub(super) kind: IntErrorKind,
75}
76
77#[stable(feature = "int_error_matching", since = "1.55.0")]
89#[cfg_attr(not(feature = "ferrocene_certified"), derive(Debug, Clone, PartialEq, Eq, Copy, Hash))]
90#[non_exhaustive]
91pub enum IntErrorKind {
92 #[stable(feature = "int_error_matching", since = "1.55.0")]
96 Empty,
97 #[stable(feature = "int_error_matching", since = "1.55.0")]
105 InvalidDigit,
106 #[stable(feature = "int_error_matching", since = "1.55.0")]
108 PosOverflow,
109 #[stable(feature = "int_error_matching", since = "1.55.0")]
111 NegOverflow,
112 #[stable(feature = "int_error_matching", since = "1.55.0")]
117 Zero,
118}
119
120#[cfg(not(feature = "ferrocene_certified"))]
121impl ParseIntError {
122 #[must_use]
124 #[rustc_const_stable(feature = "const_int_from_str", since = "1.82.0")]
125 #[stable(feature = "int_error_matching", since = "1.55.0")]
126 pub const fn kind(&self) -> &IntErrorKind {
127 &self.kind
128 }
129}
130
131#[stable(feature = "rust1", since = "1.0.0")]
132#[cfg(not(feature = "ferrocene_certified"))]
133impl fmt::Display for ParseIntError {
134 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
135 match self.kind {
136 IntErrorKind::Empty => "cannot parse integer from empty string",
137 IntErrorKind::InvalidDigit => "invalid digit found in string",
138 IntErrorKind::PosOverflow => "number too large to fit in target type",
139 IntErrorKind::NegOverflow => "number too small to fit in target type",
140 IntErrorKind::Zero => "number would be zero for non-zero type",
141 }
142 .fmt(f)
143 }
144}
145
146#[stable(feature = "rust1", since = "1.0.0")]
147#[cfg(not(feature = "ferrocene_certified"))]
148impl Error for ParseIntError {}