-
Notifications
You must be signed in to change notification settings - Fork 82
/
Copy pathgenerics.rs
75 lines (58 loc) · 1.02 KB
/
generics.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
use builtin::*;
use builtin_macros::*;
verus! {
fn main() {
}
spec fn f<A>(a1: A, a2: A) -> bool {
true
}
spec fn id<A, B>(a: A, b: B, c: A) -> A {
a
}
fn id_exec<A, B>(a: A, b: B, c: A) -> (r: A)
requires
f(a, c),
ensures
f(r, a),
{
a
}
spec fn id_int(i: int) -> int {
id(i, true, 10)
}
spec fn id_u64(i: u64) -> u64 {
id(i, true, 10)
}
fn id_u64_exec(i: u64) -> (r: u64)
ensures
f(r, id_u64(i)),
{
id_exec(i, true, 10)
}
struct S<A> {
n: A,
}
spec fn s_property<B>(s: S<B>) -> int {
7
}
spec fn id_s(s: S<int>) -> S<int> {
id(s, true, s)
}
proof fn s_prop1(x: S<int>, y: S<int>) {
assert(s_property(x) == s_property(y));
}
proof fn s_prop2<C>(x: S<C>, y: S<C>) {
assert(s_property(x) == s_property(y));
}
#[verifier::opaque]
spec fn g<A>(a: A) -> A {
a
}
proof fn test_g1(u: u8) {
reveal(g::<u8>); // REVIEW: should reveal quantify over all A?
assert(g(u) == u);
}
proof fn test_g2(u: u8) {
assert(g(u) < 256 as int);
}
} // verus!