Files
rust/tests/ui/traits/tryfrominterror-result-comparison.rs
Kivooeo 98934707eb cleaned up some tests
Additionally, remove unused `tests/ui/auxiliary/svh-*` crates that are duplicates of `tests/ui/svh/auxiliary/svh-*`.
2025-07-13 00:03:31 +05:00

20 lines
795 B
Rust

//! 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.
//@ run-pass
#![allow(unused_must_use)] // Allow ignoring the result of the comparison for the test's purpose
use std::convert::TryFrom;
use std::num::TryFromIntError;
fn main() {
let x: u32 = 125;
// Attempt to convert u32 to u8, which should succeed as 125 fits in u8.
let y: Result<u8, TryFromIntError> = u8::try_from(x);
// Verify that the Result can be correctly compared with an Ok value.
y == Ok(125);
}