forked from verus-lang/verus
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.rs
More file actions
133 lines (112 loc) · 3.02 KB
/
Copy pathfunctions.rs
File metadata and controls
133 lines (112 loc) · 3.02 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#![feature(rustc_private)]
#[macro_use]
mod common;
use common::*;
test_verify_one_file! {
#[test] test_use_fun_ext verus_code! {
proof fn test_use_fun_ext(f: spec_fn(int) -> int) {
assert((|i: int| i + 1) =~= (|i: int| 1 + i));
}
} => Ok(())
}
test_verify_one_file! {
#[test] test_use_fun_ext2 verus_code! {
spec fn drop<A>(f: spec_fn(int) -> A, k: nat) -> spec_fn(int) -> A {
|n: int| f(n + k)
}
/// prove a rule for simplifying drop(drop(f, ...))
proof fn test_use_fun_ext2<A>(f: spec_fn(int) -> A, k1: nat, k2: nat)
ensures drop(drop(f, k1), k2) == drop(f, k1 + k2)
{
assert(drop(drop(f, k1), k2) =~= drop(f, k1 + k2));
}
} => Ok(())
}
test_verify_one_file! {
#[test] test_ensures_returns_default_regression_392_1 verus_code! {
fn returns_nothing(a: u8, b: u8)
requires a == b,
ensures a == b,
{
}
fn test() {
let x: () = returns_nothing(0, 0);
assert(x == ());
}
} => Ok(())
}
test_verify_one_file! {
#[test] test_ensures_returns_default_regression_497 verus_code! {
trait Foo {
exec fn foo(&self);
}
struct X;
impl Foo for X {
exec fn foo(&self) {
// do nothing
}
}
exec fn bar() {
let z: X = X;
let x: () = z.foo();
}
} => Ok(())
}
test_verify_one_file! {
#[test] test_ensures_returns_default_regression_392_2 verus_code! {
spec fn foo() -> bool { true }
fn returns_unit() ensures foo() { }
fn test(b: bool) {
let x: ();
if b {
x = returns_unit();
}
}
} => Ok(())
}
test_verify_one_file! {
#[test] test_ensures_returns_default_regression_392_3 verus_code! {
spec fn foo() -> bool { true }
fn returns_unit() ensures foo() { }
fn takes_unit(u: ()) { }
fn test(b: bool) {
takes_unit(returns_unit());
}
} => Ok(())
}
test_verify_one_file! {
#[test] test_returns_named_unit verus_code! {
proof fn test() -> (u: ())
ensures u == ()
{
}
} => Ok(())
}
test_verify_one_file! {
#[test] test_async_external_fn_accepted verus_code! {
#[verifier(external)]
async fn foo(_c: usize) -> Result<usize, ()> {
Ok(21)
}
} => Ok(())
}
test_verify_one_file! {
#[test] test_non_async_opaque_types_disallowed verus_code! {
trait Foo {
fn bar(&self) -> bool;
}
type OT = impl Foo;
} => Err(err) => {
assert!(err.errors.iter().find(|p| p.message == "`impl Trait` in type aliases is unstable").is_some());
}
}
test_verify_one_file! {
#[test] test_ensures_name_collision verus_code! {
fn test_fn() -> (test_fn: i32)
ensures
test_fn == 42,
{
42
}
} => Ok(())
}