2025-07-01 20:20:14 +05:00
|
|
|
//! This test verifies that `std::num::TryFromIntError` correctly implements `PartialEq`,
|
|
|
|
|
//! allowing `Result<T, TryFromIntError>` values to be compared for equality using `==`.
|
|
|
|
|
//! It specifically checks a successful numeric conversion scenario where the `Result::Ok`
|
|
|
|
|
//! variant is compared, ensuring that the comparison yields the expected boolean result.
|
|
|
|
|
|
2024-02-16 20:02:50 +00:00
|
|
|
//@ run-pass
|
2019-07-27 00:54:25 +03:00
|
|
|
|
2025-07-01 20:20:14 +05:00
|
|
|
#![allow(unused_must_use)] // Allow ignoring the result of the comparison for the test's purpose
|
2018-08-18 23:24:25 +02:00
|
|
|
|
|
|
|
|
use std::convert::TryFrom;
|
|
|
|
|
use std::num::TryFromIntError;
|
|
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
|
let x: u32 = 125;
|
2025-07-01 20:20:14 +05:00
|
|
|
// Attempt to convert u32 to u8, which should succeed as 125 fits in u8.
|
2018-08-18 23:24:25 +02:00
|
|
|
let y: Result<u8, TryFromIntError> = u8::try_from(x);
|
2025-07-01 20:20:14 +05:00
|
|
|
// Verify that the Result can be correctly compared with an Ok value.
|
2018-08-18 23:24:25 +02:00
|
|
|
y == Ok(125);
|
|
|
|
|
}
|