Skip to content

Commit ad2d93d

Browse files
committed
Apply suggested changes
1 parent 75e6dee commit ad2d93d

File tree

10 files changed

+48
-25
lines changed

10 files changed

+48
-25
lines changed

compiler/rustc_middle/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
#![feature(crate_visibility_modifier)]
4747
#![feature(associated_type_bounds)]
4848
#![feature(rustc_attrs)]
49+
#![feature(int_error_matching)]
4950
#![recursion_limit = "512"]
5051

5152
#[macro_use]

compiler/rustc_middle/src/middle/limits.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,10 @@ fn update_limit(
5050
let error_str = match e.kind() {
5151
IntErrorKind::PosOverflow => "`limit` is too large",
5252
IntErrorKind::Empty => "`limit` must be a non-negative integer",
53-
IntErrorKind::InvalidDigit(_) => "not a valid integer",
54-
IntErrorKind::NegOverflow => bug!("`limit` should never underflow"),
53+
IntErrorKind::InvalidDigit => "not a valid integer",
54+
IntErrorKind::NegOverflow => {
55+
bug!("`limit` should never negatively underflow")
56+
}
5557
IntErrorKind::Zero => bug!("zero is a valid `limit`"),
5658
kind => bug!("unimplemented IntErrorKind variant: {:?}", kind),
5759
};

library/core/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@
151151
#![feature(slice_ptr_get)]
152152
#![feature(no_niche)] // rust-lang/rust#68303
153153
#![feature(unsafe_block_in_unsafe_fn)]
154+
#![feature(int_error_matching)]
154155
#![deny(unsafe_op_in_unsafe_fn)]
155156

156157
#[prelude_import]

library/core/src/num/error.rs

+16-9
Original file line numberDiff line numberDiff line change
@@ -77,20 +77,26 @@ pub struct ParseIntError {
7777
/// # Example
7878
///
7979
/// ```
80+
/// #![feature(int_error_matching)]
81+
///
8082
/// # fn main() {
8183
/// if let Err(e) = i32::from_str_radix("a12", 10) {
8284
/// println!("Failed conversion to i32: {:?}", e.kind());
8385
/// }
8486
/// # }
8587
/// ```
86-
#[stable(feature = "int_error_matching", since = "1.47.0")]
88+
#[unstable(
89+
feature = "int_error_matching",
90+
reason = "it can be useful to match errors when making error messages \
91+
for integer parsing",
92+
issue = "22639"
93+
)]
8794
#[derive(Debug, Clone, PartialEq, Eq)]
8895
#[non_exhaustive]
8996
pub enum IntErrorKind {
9097
/// Value being parsed is empty.
9198
///
9299
/// Among other causes, this variant will be constructed when parsing an empty string.
93-
#[stable(feature = "int_error_matching", since = "1.47.0")]
94100
Empty,
95101
/// Contains an invalid digit in its context.
96102
///
@@ -99,25 +105,26 @@ pub enum IntErrorKind {
99105
///
100106
/// This variant is also constructed when a `+` or `-` is misplaced within a string
101107
/// either on its own or in the middle of a number.
102-
#[stable(feature = "int_error_matching", since = "1.47.0")]
103-
InvalidDigit(#[stable(feature = "int_error_matching", since = "1.47.0")] char),
108+
InvalidDigit,
104109
/// Integer is too large to store in target integer type.
105-
#[stable(feature = "int_error_matching", since = "1.47.0")]
106110
PosOverflow,
107111
/// Integer is too small to store in target integer type.
108-
#[stable(feature = "int_error_matching", since = "1.47.0")]
109112
NegOverflow,
110113
/// Value was Zero
111114
///
112115
/// This variant will be emitted when the parsing string has a value of zero, which
113116
/// would be illegal for non-zero types.
114-
#[stable(feature = "int_error_matching", since = "1.47.0")]
115117
Zero,
116118
}
117119

118120
impl ParseIntError {
119121
/// Outputs the detailed cause of parsing an integer failing.
120-
#[stable(feature = "int_error_matching", since = "1.47.0")]
122+
#[unstable(
123+
feature = "int_error_matching",
124+
reason = "it can be useful to match errors when making error messages \
125+
for integer parsing",
126+
issue = "22639"
127+
)]
121128
pub fn kind(&self) -> &IntErrorKind {
122129
&self.kind
123130
}
@@ -131,7 +138,7 @@ impl ParseIntError {
131138
pub fn __description(&self) -> &str {
132139
match self.kind {
133140
IntErrorKind::Empty => "cannot parse integer from empty string",
134-
IntErrorKind::InvalidDigit(_) => "invalid digit found in string",
141+
IntErrorKind::InvalidDigit => "invalid digit found in string",
135142
IntErrorKind::PosOverflow => "number too large to fit in target type",
136143
IntErrorKind::NegOverflow => "number too small to fit in target type",
137144
IntErrorKind::Zero => "number would be zero for non-zero type",

library/core/src/num/mod.rs

+9-4
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,12 @@ pub use nonzero::{NonZeroI128, NonZeroI16, NonZeroI32, NonZeroI64, NonZeroI8, No
6363
#[stable(feature = "try_from", since = "1.34.0")]
6464
pub use error::TryFromIntError;
6565

66-
#[stable(feature = "int_error_matching", since = "1.47.0")]
66+
#[unstable(
67+
feature = "int_error_matching",
68+
reason = "it can be useful to match errors when making error messages \
69+
for integer parsing",
70+
issue = "22639"
71+
)]
6772
pub use error::IntErrorKind;
6873

6974
macro_rules! usize_isize_to_xe_bytes_doc {
@@ -831,7 +836,7 @@ fn from_str_radix<T: FromStrRadixHelper>(src: &str, radix: u32) -> Result<T, Par
831836

832837
let (is_positive, digits) = match src[0] {
833838
b'+' | b'-' if src[1..].is_empty() => {
834-
return Err(PIE { kind: InvalidDigit(src[0] as char) });
839+
return Err(PIE { kind: InvalidDigit });
835840
}
836841
b'+' => (true, &src[1..]),
837842
b'-' if is_signed_ty => (false, &src[1..]),
@@ -844,7 +849,7 @@ fn from_str_radix<T: FromStrRadixHelper>(src: &str, radix: u32) -> Result<T, Par
844849
for &c in digits {
845850
let x = match (c as char).to_digit(radix) {
846851
Some(x) => x,
847-
None => return Err(PIE { kind: InvalidDigit(c as char) }),
852+
None => return Err(PIE { kind: InvalidDigit }),
848853
};
849854
result = match result.checked_mul(radix) {
850855
Some(result) => result,
@@ -860,7 +865,7 @@ fn from_str_radix<T: FromStrRadixHelper>(src: &str, radix: u32) -> Result<T, Par
860865
for &c in digits {
861866
let x = match (c as char).to_digit(radix) {
862867
Some(x) => x,
863-
None => return Err(PIE { kind: InvalidDigit(c as char) }),
868+
None => return Err(PIE { kind: InvalidDigit }),
864869
};
865870
result = match result.checked_mul(radix) {
866871
Some(result) => result,

library/core/tests/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#![feature(try_trait)]
3838
#![feature(slice_internals)]
3939
#![feature(slice_partition_dedup)]
40+
#![feature(int_error_matching)]
4041
#![feature(array_value_iter)]
4142
#![feature(iter_partition_in_place)]
4243
#![feature(iter_is_partitioned)]

library/core/tests/nonzero.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ fn test_from_str() {
131131
assert_eq!("0".parse::<NonZeroU8>().err().map(|e| e.kind().clone()), Some(IntErrorKind::Zero));
132132
assert_eq!(
133133
"-1".parse::<NonZeroU8>().err().map(|e| e.kind().clone()),
134-
Some(IntErrorKind::InvalidDigit('-'))
134+
Some(IntErrorKind::InvalidDigit)
135135
);
136136
assert_eq!(
137137
"-129".parse::<NonZeroI8>().err().map(|e| e.kind().clone()),

library/core/tests/num/mod.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -118,14 +118,14 @@ fn test_leading_plus() {
118118

119119
#[test]
120120
fn test_invalid() {
121-
test_parse::<i8>("--129", Err(IntErrorKind::InvalidDigit('-')));
122-
test_parse::<i8>("++129", Err(IntErrorKind::InvalidDigit('+')));
123-
test_parse::<u8>("Съешь", Err(IntErrorKind::InvalidDigit('Ð')));
124-
test_parse::<u8>("123Hello", Err(IntErrorKind::InvalidDigit('H')));
125-
test_parse::<i8>("--", Err(IntErrorKind::InvalidDigit('-')));
126-
test_parse::<i8>("-", Err(IntErrorKind::InvalidDigit('-')));
127-
test_parse::<i8>("+", Err(IntErrorKind::InvalidDigit('+')));
128-
test_parse::<u8>("-1", Err(IntErrorKind::InvalidDigit('-')));
121+
test_parse::<i8>("--129", Err(IntErrorKind::InvalidDigit));
122+
test_parse::<i8>("++129", Err(IntErrorKind::InvalidDigit));
123+
test_parse::<u8>("Съешь", Err(IntErrorKind::InvalidDigit));
124+
test_parse::<u8>("123Hello", Err(IntErrorKind::InvalidDigit));
125+
test_parse::<i8>("--", Err(IntErrorKind::InvalidDigit));
126+
test_parse::<i8>("-", Err(IntErrorKind::InvalidDigit));
127+
test_parse::<i8>("+", Err(IntErrorKind::InvalidDigit));
128+
test_parse::<u8>("-1", Err(IntErrorKind::InvalidDigit));
129129
}
130130

131131
#[test]

library/std/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@
264264
#![feature(global_asm)]
265265
#![feature(hashmap_internals)]
266266
#![feature(int_error_internals)]
267+
#![feature(int_error_matching)]
267268
#![feature(integer_atomics)]
268269
#![feature(into_future)]
269270
#![feature(lang_items)]

library/std/src/num.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,12 @@ pub use core::num::{NonZeroI128, NonZeroI16, NonZeroI32, NonZeroI64, NonZeroI8,
2222
#[stable(feature = "nonzero", since = "1.28.0")]
2323
pub use core::num::{NonZeroU128, NonZeroU16, NonZeroU32, NonZeroU64, NonZeroU8, NonZeroUsize};
2424

25-
#[stable(feature = "int_error_matching", since = "1.47.0")]
25+
#[unstable(
26+
feature = "int_error_matching",
27+
reason = "it can be useful to match errors when making error messages \
28+
for integer parsing",
29+
issue = "22639"
30+
)]
2631
pub use core::num::IntErrorKind;
2732

2833
#[cfg(test)]

0 commit comments

Comments
 (0)