Skip to content

Commit 6bc8168

Browse files
committed
try-from-int-error-partial-eq
1 parent 16daaa6 commit 6bc8168

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed
Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
1+
//! This test verifies that `std::num::TryFromIntError` correctly implements `PartialEq`,
2+
//! allowing `Result<T, TryFromIntError>` values to be compared for equality using `==`.
3+
//! It specifically checks a successful numeric conversion scenario where the `Result::Ok`
4+
//! variant is compared, ensuring that the comparison yields the expected boolean result.
5+
16
//@ run-pass
27

3-
#![allow(unused_must_use)]
8+
#![allow(unused_must_use)] // Allow ignoring the result of the comparison for the test's purpose
49

510
use std::convert::TryFrom;
611
use std::num::TryFromIntError;
712

813
fn main() {
914
let x: u32 = 125;
15+
// Attempt to convert u32 to u8, which should succeed as 125 fits in u8.
1016
let y: Result<u8, TryFromIntError> = u8::try_from(x);
17+
// Verify that the Result can be correctly compared with an Ok value.
1118
y == Ok(125);
1219
}

0 commit comments

Comments
 (0)