forked from verus-lang/verus
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontrib.rs
More file actions
84 lines (76 loc) · 2.04 KB
/
contrib.rs
File metadata and controls
84 lines (76 loc) · 2.04 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
#![feature(rustc_private)]
#[macro_use]
mod common;
use common::*;
// Adapted from auto_spec tests in syntax_attr.rs
test_verify_one_file! {
#[test] test_auto_spec verus_code! {
#[vstd::contrib::auto_spec]
pub fn f(x: u32, y: u32) -> u32
requires
x < 100,
y < 100,
{
proof {
assert(true);
}
x + y
}
#[vstd::contrib::auto_spec]
pub fn f2(x: u32) -> u32
requires
x < 100,
{
f(x, 1)
}
struct S;
impl S {
#[vstd::contrib::auto_spec]
fn foo(&self, x: u32) -> u32 {
x / 2
}
}
proof fn lemma_f(x: u32, y: u32)
requires
x < 100,
ensures
y == 1 ==> f(x, y) == f2(x),
f(x, y) == f(y, x),
f2(x) == f2(x),
f(x, y) == (x + y) as u32,
f2(x) == x + 1,
{}
mod inner {
use super::*;
proof fn lemma_f(x: u32)
requires
x < 100,
ensures
f2(x) == (x + 1),
{}
}
} => Ok(())
}
test_verify_one_file_with_options! {
#[test] test_auto_spec_missing_use ["no-auto-import-verus_builtin"] => verus_code! {
// fails if we don't say "use vstd::contrib::auto_spec;"
#[auto_spec]
fn foo(x: u32) -> u32 {
x / 2
}
} => Err(e) => assert_vir_error_msg(e, "cannot find attribute `auto_spec` in this scope")
}
test_verify_one_file! {
#[test] test_auto_spec_unsupported_body verus_code! {
use vstd::contrib::auto_spec;
#[auto_spec]
fn f(x: &mut u32, y: u32) -> u32
requires
*x < 100,
y < 100,
{
*x = *x + y;
*x
}
} => Err(e) => assert_vir_error_msg(e, "allow_in_spec not supported for function with &mut param")
}