-
Notifications
You must be signed in to change notification settings - Fork 78
/
Copy pathresults.rs
54 lines (44 loc) · 1.41 KB
/
results.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#![feature(rustc_private)]
#[macro_use]
mod common;
use common::*;
test_verify_one_file! {
#[test] test1 verus_code! {
use vstd::prelude::*;
struct Err {
error_code: int,
}
// Result::unwrap and Result::unwrap_err require trait bounds
use core::fmt::Debug;
#[verifier::external]
impl Debug for Err {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> Result<(), core::fmt::Error> {
unimplemented!();
}
}
proof fn test_result() {
let ok_result = Result::<i8, Err>::Ok(1);
assert(ok_result.is_Ok());
assert(ok_result.unwrap() == 1);
let err_result = Result::<i8, Err>::Err(Err{ error_code: -1 });
assert(err_result.is_Err());
assert(err_result.get_Err_0() == Err{ error_code: -1 });
}
} => Ok(())
}
test_verify_one_file! {
#[test] test1_fails1 verus_code! {
use vstd::prelude::*;
struct Err {
error_code: int,
}
proof fn test_ok_result() {
let ok_result = Result::<int, Err>::Ok(1);
assert(ok_result.is_Err()); // FAILS
}
proof fn test_err_result() {
let err_result = Result::<int, Err>::Err(Err{ error_code: -1 });
assert(err_result.is_Ok()); // FAILS
}
} => Err(err) => assert_fails(err, 2)
}