-
Notifications
You must be signed in to change notification settings - Fork 78
/
Copy pathstructural.rs
86 lines (72 loc) · 2.25 KB
/
structural.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
#![feature(rustc_private)]
#[macro_use]
mod common;
use common::*;
const STRUCTS: &str = verus_code_str! {
#[derive(PartialEq, Eq, Structural)]
struct Car {
four_doors: bool,
passengers: u64,
}
#[derive(PartialEq, Eq, Structural)]
enum Vehicle {
Car(Car),
Train(bool),
}
};
test_verify_one_file! {
#[test] test_structural_eq STRUCTS.to_string() + verus_code_str! {
fn test_structural_eq(passengers: u64) {
let c1 = Car { passengers, four_doors: true };
let c2 = Car { passengers, four_doors: false };
let c3 = Car { passengers, four_doors: true };
assert(c1 == c3);
assert(c1 != c2);
let t = Vehicle::Train(true);
let ca = Vehicle::Car(c1);
assert(t != ca);
assert(t == ca); // FAILS
}
} => Err(err) => assert_one_fails(err)
}
test_verify_one_file! {
#[test] test_not_structural_eq code! {
#[derive(PartialEq, Eq)]
struct Thing {
v: bool,
}
fn test_not_structural(passengers: u64) {
let v1 = Thing { v: true };
let v2 = Thing { v: true };
assert_(v1 == v2);
}
} => Err(err) => assert_vir_error_msg(err, "==/!= for non smt equality types")
}
test_verify_one_file! {
#[test] test_not_structural_generic verus_code! {
#[derive(PartialEq, Eq, Structural)]
struct Thing<V> {
v: V,
}
#[derive(Eq, Structural)]
struct Other { }
impl std::cmp::PartialEq for Other {
fn eq(&self, _: &Self) -> bool { todo!() }
}
fn test_not_structural(passengers: u64) {
let v1 = Thing { v: true };
let v2 = Thing { v: true };
assert(v1 == v2);
}
} => Err(err) => assert_vir_error_msg(err, "structural impl for non-structural type Other")
}
test_verify_one_file! {
#[test] test_not_structural_fields verus_code! {
#[derive(PartialEq, Eq)]
struct Other { }
#[derive(PartialEq, Eq, Structural)]
struct Thing {
o: Other,
}
} => Err(err) => assert_rust_error_msg(err, "the trait bound `Other: builtin::Structural` is not satisfied")
}