-
Notifications
You must be signed in to change notification settings - Fork 78
/
Copy pathexpr_stmts.rs
90 lines (80 loc) · 1.87 KB
/
expr_stmts.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
#![feature(rustc_private)]
#[macro_use]
mod common;
use common::*;
test_verify_one_file! {
#[test] test_stmts_expr_1 verus_code! {
fn id(v: u64) -> (ret: u64)
ensures v == ret
{
v
}
fn test1() {
let mut a = 12;
let b = id({
a = a + 1;
a
});
assert(b == 13);
}
} => Ok(())
}
test_verify_one_file! {
#[test] test_stmts_expr_2 verus_code! {
fn id(v: &u64) -> (ret: u64)
ensures *v == ret
{
*v
}
fn test1() {
let mut a = 12;
let b = id({
a = a + 1;
&a
});
assert(b == 13);
}
} => Ok(())
}
test_verify_one_file! {
#[ignore] #[test] test_stmts_expr_3 verus_code! {
fn id(v: &mut u64)
ensures *v == *old(v)
{
}
fn test1() {
let mut a = 12;
// this may or may not be supported later, it is intentionally unsupported now
id({
a = a + 1;
&mut a
});
assert(a == 13);
}
} => Ok(())
}
test_verify_one_file! {
#[ignore] #[test] test_stmts_expr_ref_mut verus_code! {
#[derive(Debug)]
struct A {
v: u64,
}
fn ret_ref_mut(a: &mut A) -> &mut u64 {
&mut a.v
}
fn transform(v: &mut u64) {
*v += 1;
println!("{}", v);
}
fn main() {
let mut a = A { v: 23 };
// this may or may not be supported later, it is intentionally unsupported now
transform({
let b = &mut a;
b.v += 2;
ret_ref_mut(b)
});
println!("{:?}", a)
}
} => Ok(())
}