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