Skip to content

Commit 814ae64

Browse files
committed
add: tests of annotations for functions that receive structs as arguments
1 parent 0735236 commit 814ae64

2 files changed

Lines changed: 64 additions & 0 deletions

File tree

tests/ui/pass/annot_preds_impl.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//@check-pass
2+
//@compile-flags: -Adead_code -C debug-assertions=off
3+
4+
// A is represented as Tuple<Int> in SMT-LIB2 format.
5+
struct A {
6+
x: i64,
7+
}
8+
9+
impl A {
10+
// Support annotations for metheds in impl blocks
11+
12+
#[thrust::predicate]
13+
fn is_double(&self, doubled: &Self) -> bool {
14+
// (tuple_proj<Int>.0 self) is equivalent to self.x
15+
// self.x * 2 == doubled.x is written as following:
16+
"(=
17+
(* (tuple_proj<Int>.0 self) 2)
18+
(tuple_proj<Int>.0 doubled)
19+
)"; true
20+
}
21+
22+
#[thrust::requires(true)]
23+
#[thrust::ensures(*self.is_double(^self))]
24+
fn double(&mut self) {
25+
self.x += self.x;
26+
}
27+
}
28+
29+
fn main() {
30+
let mut a = A { x: 3 };
31+
a.double();
32+
assert!(a.x == 6);
33+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//@check-pass
2+
//@compile-flags: -Adead_code -C debug-assertions=off
3+
4+
// This is an alternative version of `annot_preds_impl.rs` without `impl` blocks.
5+
6+
// A is represented as Tuple<Int> in SMT-LIB2 format.
7+
struct A {
8+
x: i64,
9+
}
10+
11+
#[thrust::predicate]
12+
fn is_double(a: &A, doubled: &A) -> bool {
13+
// (tuple_proj<Int>.0 a) is equivalent to a.x
14+
// a.x * 2 == doubled.x is written as following:
15+
"(=
16+
(* (tuple_proj<Int>.0 a) 2)
17+
(tuple_proj<Int>.0 doubled)
18+
)"; true
19+
}
20+
21+
#[thrust::requires(true)]
22+
#[thrust::ensures(is_double(*a, ^a))]
23+
fn double(a: &mut A) {
24+
a.x += a.x;
25+
}
26+
27+
fn main() {
28+
let mut a = A{x: 3};
29+
double(&mut a);
30+
assert!(a.x == 6);
31+
}

0 commit comments

Comments
 (0)