Skip to content

Commit e1d5509

Browse files
committed
Added comments providing justification for support of calling deref_* with wrong variant
1 parent c025fde commit e1d5509

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/libcore/tests/result.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,11 @@ fn test_result_deref() {
290290
let expected_result = Result::Err::<&u32, &[i32]>(&[5, 4, 3, 2, 1][..]);
291291
assert_eq!(ref_err.deref(), expected_result);
292292

293-
// *Odd corner cases (tested for completeness)*
293+
// The following cases test calling deref_* with the wrong variant (i.e.
294+
// `deref_ok()` with a `Result::Err()`, or `deref_err()` with a `Result::Ok()`.
295+
// While unusual, these cases are supported to ensure that an `inner_deref`
296+
// call can still be made even when one of the Result types does not implement
297+
// `Deref` (for example, std::io::Error).
294298

295299
// &Result<T, E: Deref>::Ok(T).deref_err() ->
296300
// Result<&T, &E::Deref::Target>::Ok(&T)

0 commit comments

Comments
 (0)