From 19577f55ed2e0822054ba1e77bfbb2caf433e265 Mon Sep 17 00:00:00 2001 From: Shun Sakai Date: Mon, 19 Oct 2026 08:38:14 +0900 Subject: [PATCH 1/2] feat!: change return type of `TryFromIntError::kind` --- library/core/src/num/error.rs | 4 ++-- library/coretests/tests/nonzero.rs | 8 ++++---- library/coretests/tests/num/mod.rs | 22 +++++++++++----------- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/library/core/src/num/error.rs b/library/core/src/num/error.rs index 6a8a2d5b636ed..5bc987f8069f5 100644 --- a/library/core/src/num/error.rs +++ b/library/core/src/num/error.rs @@ -12,8 +12,8 @@ impl TryFromIntError { /// Outputs the detailed cause of converting an integer failing. #[must_use] #[unstable(feature = "try_from_int_error_kind", issue = "153978")] - pub const fn kind(&self) -> &IntErrorKind { - &self.0 + pub const fn kind(&self) -> IntErrorKind { + self.0 } } diff --git a/library/coretests/tests/nonzero.rs b/library/coretests/tests/nonzero.rs index 5efc09fd2d98e..37041e22d0dfd 100644 --- a/library/coretests/tests/nonzero.rs +++ b/library/coretests/tests/nonzero.rs @@ -285,11 +285,11 @@ fn test_nonzero_from_int_on_success() { #[test] fn test_nonzero_from_int_on_err() { - assert_eq!(NonZero::::try_from(0).unwrap_err().kind(), &IntErrorKind::Zero); - assert_eq!(NonZero::::try_from(0).unwrap_err().kind(), &IntErrorKind::Zero); + assert_eq!(NonZero::::try_from(0).unwrap_err().kind(), IntErrorKind::Zero); + assert_eq!(NonZero::::try_from(0).unwrap_err().kind(), IntErrorKind::Zero); - assert_eq!(NonZero::::try_from(0).unwrap_err().kind(), &IntErrorKind::Zero); - assert_eq!(NonZero::::try_from(0).unwrap_err().kind(), &IntErrorKind::Zero); + assert_eq!(NonZero::::try_from(0).unwrap_err().kind(), IntErrorKind::Zero); + assert_eq!(NonZero::::try_from(0).unwrap_err().kind(), IntErrorKind::Zero); } #[test] diff --git a/library/coretests/tests/num/mod.rs b/library/coretests/tests/num/mod.rs index f892734d8b95d..f258c77261f3f 100644 --- a/library/coretests/tests/num/mod.rs +++ b/library/coretests/tests/num/mod.rs @@ -388,17 +388,17 @@ macro_rules! test_impl_try_from_integer_to_bool { let zero: $source = 0; let one: $source = 1; let two: $source = 2; - assert_eq!(bool::try_from(max).unwrap_err().kind(), &IntErrorKind::PosOverflow); + assert_eq!(bool::try_from(max).unwrap_err().kind(), IntErrorKind::PosOverflow); if min != 0 { - assert_eq!(bool::try_from(min).unwrap_err().kind(), &IntErrorKind::NegOverflow); + assert_eq!(bool::try_from(min).unwrap_err().kind(), IntErrorKind::NegOverflow); assert_eq!( bool::try_from(zero - 1).unwrap_err().kind(), - &IntErrorKind::NegOverflow + IntErrorKind::NegOverflow ); } assert_eq!(bool::try_from(zero).unwrap(), false); assert_eq!(bool::try_from(one).unwrap(), true); - assert_eq!(bool::try_from(two).unwrap_err().kind(), &IntErrorKind::PosOverflow); + assert_eq!(bool::try_from(two).unwrap_err().kind(), IntErrorKind::PosOverflow); } }; } @@ -540,12 +540,12 @@ macro_rules! test_impl_try_from_signed_to_unsigned_upper_ok { assert_eq!(<$target as TryFrom<$source>>::try_from(max).unwrap(), max as $target); assert_eq!( <$target as TryFrom<$source>>::try_from(min).unwrap_err().kind(), - &IntErrorKind::NegOverflow + IntErrorKind::NegOverflow ); assert_eq!(<$target as TryFrom<$source>>::try_from(zero).unwrap(), zero as $target); assert_eq!( <$target as TryFrom<$source>>::try_from(neg_one).unwrap_err().kind(), - &IntErrorKind::NegOverflow + IntErrorKind::NegOverflow ); } }; @@ -609,7 +609,7 @@ macro_rules! test_impl_try_from_unsigned_to_signed_upper_err { let zero: $source = 0; assert_eq!( <$target as TryFrom<$source>>::try_from(max).unwrap_err().kind(), - &IntErrorKind::PosOverflow + IntErrorKind::PosOverflow ); assert_eq!(<$target as TryFrom<$source>>::try_from(min).unwrap(), min as $target); assert_eq!(<$target as TryFrom<$source>>::try_from(zero).unwrap(), zero as $target); @@ -675,12 +675,12 @@ macro_rules! test_impl_try_from_same_sign_err { let t_min = <$target>::MIN; assert_eq!( <$target as TryFrom<$source>>::try_from(max).unwrap_err().kind(), - &IntErrorKind::PosOverflow + IntErrorKind::PosOverflow ); if min != 0 { assert_eq!( <$target as TryFrom<$source>>::try_from(min).unwrap_err().kind(), - &IntErrorKind::NegOverflow + IntErrorKind::NegOverflow ); } assert_eq!(<$target as TryFrom<$source>>::try_from(zero).unwrap(), zero as $target); @@ -770,11 +770,11 @@ macro_rules! test_impl_try_from_signed_to_unsigned_err { let t_min = <$target>::MIN; assert_eq!( <$target as TryFrom<$source>>::try_from(max).unwrap_err().kind(), - &IntErrorKind::PosOverflow + IntErrorKind::PosOverflow ); assert_eq!( <$target as TryFrom<$source>>::try_from(min).unwrap_err().kind(), - &IntErrorKind::NegOverflow + IntErrorKind::NegOverflow ); assert_eq!(<$target as TryFrom<$source>>::try_from(zero).unwrap(), zero as $target); assert_eq!( From 104e47aa6d20a8583bd5efbb224af32615871f3b Mon Sep 17 00:00:00 2001 From: Shun Sakai Date: Mon, 19 Oct 2026 09:17:23 +0900 Subject: [PATCH 2/2] style: apply `rustfmt` --- library/coretests/tests/num/mod.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/library/coretests/tests/num/mod.rs b/library/coretests/tests/num/mod.rs index f258c77261f3f..46e5ee0213b04 100644 --- a/library/coretests/tests/num/mod.rs +++ b/library/coretests/tests/num/mod.rs @@ -391,10 +391,7 @@ macro_rules! test_impl_try_from_integer_to_bool { assert_eq!(bool::try_from(max).unwrap_err().kind(), IntErrorKind::PosOverflow); if min != 0 { assert_eq!(bool::try_from(min).unwrap_err().kind(), IntErrorKind::NegOverflow); - assert_eq!( - bool::try_from(zero - 1).unwrap_err().kind(), - IntErrorKind::NegOverflow - ); + assert_eq!(bool::try_from(zero - 1).unwrap_err().kind(), IntErrorKind::NegOverflow); } assert_eq!(bool::try_from(zero).unwrap(), false); assert_eq!(bool::try_from(one).unwrap(), true);