-
Notifications
You must be signed in to change notification settings - Fork 78
/
Copy pathtest_expand_errors.rs
238 lines (185 loc) · 3.83 KB
/
test_expand_errors.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
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
// rust_verify/tests/example.rs expand-errors
#![allow(unused_imports)]
use builtin::*;
use builtin_macros::*;
use vstd::map::*;
use vstd::modes::*;
use vstd::prelude::*;
use vstd::seq::*;
use vstd::*;
verus! {
spec fn e() -> bool;
spec fn f() -> bool;
spec fn g() -> bool;
spec fn h() -> bool;
spec fn k(i: int) -> bool;
spec fn z() -> bool {
(e() ==> h()) && (forall|i: int| k(i))
}
spec fn stuff() -> bool {
f() && g() && z()
}
proof fn test()
requires
f(),
{
assert(stuff());
}
proof fn test_ret()
ensures
z(),
{
}
pub spec fn ai(i: int) -> bool;
pub spec fn bi(i: int) -> bool;
pub spec fn ci(i: int) -> bool;
pub open spec fn all_a() -> bool {
forall|i: int| ai(i)
}
pub open spec fn all_b() -> bool {
forall|i: int| bi(i)
}
pub open spec fn all_c() -> bool {
forall|i: int| ci(i)
}
pub proof fn test2(j: int)
requires
forall|i: int| ai(i),
forall|i: int| (#[trigger] ai(i)) ==> bi(i),
{
assert(ai(j) && bi(j) && ci(j));
}
pub proof fn test_let(j: int)
requires
ai(j + 1),
{
assert({
let k = j + 3;
let r = k - 2;
ai(r) && bi(r)
});
}
pub proof fn test_match(m: Option<int>)
requires
m.is_some(),
{
assert(match m {
Some(x) => x == 5,
None => false,
});
}
pub proof fn test_match3(foo: Foo) {
assert(match foo {
Foo::Bar => false,
Foo::Qux(z) => z == 0,
Foo::Duck(w, y) => w == y,
});
}
pub proof fn test3(a: bool, b: bool) {
assert(a <==> b);
}
pub proof fn test_xor(a: bool, b: bool) {
assert(a ^ b);
}
pub proof fn test4(a: Option<u8>, b: Option<u8>) {
assert(a == b);
}
pub struct X {
pub a: u32,
pub b: bool,
pub c: u64,
}
pub proof fn test5(a: X, b: X) {
assert(a == b);
}
pub proof fn test6(a: Option<u64>, b: u64) {
assert(a == Some(b));
}
pub proof fn test7(a: Option<u64>, b: u64) {
assert(Some(b) == a);
}
pub proof fn test8(a: Option<u64>, b: u64) {
assert(a === None);
}
pub proof fn test9(a: Option<u64>, b: u64) {
assert(None === a);
}
pub proof fn test10(a: Option<u64>, b: u64) {
assert(None === Some(b));
}
pub proof fn test11(a: u64, b: u64) {
assert(Some(a) == Some(b));
}
#[verifier::external_body]
pub struct OpaqueDT {
u: u64,
}
pub proof fn test12(a: OpaqueDT, b: OpaqueDT) {
assert(a == b);
}
pub enum Foo {
Bar,
Qux(u64),
Duck(u64, u64),
}
pub proof fn test13(a: Foo, b: u64) {
assert(a == Foo::Qux(b));
}
pub proof fn test14(a: Foo, b: u64, c: u64) {
assert(Foo::Duck(b, c) == a);
}
pub proof fn test15(a: Foo) {
assert(a === Foo::Bar);
}
pub proof fn test16(a: Foo, b: u64) {
assert(Foo::Bar === a);
}
pub proof fn test17(a: u64, b: u64, c: u64) {
assert(Foo::Qux(a) === Foo::Duck(b, c));
}
pub proof fn test18(b: u64, c: u64, e: u64, f: u64) {
assert(Foo::Duck(b, c) == Foo::Duck(e, f));
}
#[verifier::opaque]
spec fn some_opaque() -> bool {
false
}
spec fn some_non_opaque() -> bool {
false
}
proof fn test_opaque1() {
assert(some_opaque());
}
proof fn test_opaque2() {
reveal(some_opaque);
assert(some_opaque());
}
proof fn test_opaque3() {
hide(some_non_opaque);
assert(some_non_opaque());
}
spec fn other(i: int) -> bool;
spec fn recursive_function(i: int, base: bool) -> bool
decreases i,
{
if i <= 0 {
base
} else {
recursive_function(i - 1, base)
}
}
proof fn test_rec() {
reveal_with_fuel(recursive_function, 3);
assert(recursive_function(3, true)); // should fail with "reached fuel limit for recursion"
}
proof fn test_rec2() {
reveal_with_fuel(recursive_function, 4);
assert(recursive_function(3, true)); // should pass
}
proof fn test_rec3() {
reveal_with_fuel(recursive_function, 4);
assert(recursive_function(3, false));
}
fn main() {
}
} // verus!