Move const tests for Result to library\core

Part of #76268
This commit is contained in:
Christiaan Dirkx 2020-09-04 00:24:34 +02:00
parent 518f1ccb72
commit 787b2707a7
2 changed files with 16 additions and 12 deletions

View File

@ -305,3 +305,19 @@ fn test_result_as_deref_mut() {
let expected_result = Result::Err::<&mut u32, &mut Vec<i32>>(&mut expected_vec);
assert_eq!(mut_err.as_deref_mut(), expected_result);
}
#[test]
fn result_const() {
// test that the methods of `Result` are usable in a const context
const RESULT: Result<usize, bool> = Ok(32);
const REF: Result<&usize, &bool> = RESULT.as_ref();
assert_eq!(REF, Ok(&32));
const IS_OK: bool = RESULT.is_ok();
assert!(IS_OK);
const IS_ERR: bool = RESULT.is_err();
assert!(!IS_ERR)
}

View File

@ -1,12 +0,0 @@
// run-pass
fn main() {
const X: Result<i32, bool> = Ok(32);
const Y: Result<&i32, &bool> = X.as_ref();
const IS_OK: bool = X.is_ok();
assert!(IS_OK);
const IS_ERR: bool = Y.is_err();
assert!(!IS_ERR)
}