diff --git a/library/core/tests/result.rs b/library/core/tests/result.rs index caa2d916cd7..d3c650669da 100644 --- a/library/core/tests/result.rs +++ b/library/core/tests/result.rs @@ -305,3 +305,19 @@ fn test_result_as_deref_mut() { let expected_result = Result::Err::<&mut u32, &mut Vec>(&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 = 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) +} diff --git a/src/test/ui/consts/const-result.rs b/src/test/ui/consts/const-result.rs deleted file mode 100644 index e548d3e79ff..00000000000 --- a/src/test/ui/consts/const-result.rs +++ /dev/null @@ -1,12 +0,0 @@ -// run-pass - -fn main() { - const X: Result = 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) -}