Skip to content

Commit 818bd1f

Browse files
committed
Add many more test cases
(thanks Claude)
1 parent db64c20 commit 818bd1f

28 files changed

Lines changed: 460 additions & 0 deletions
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//@error-in-other-file: Unsat
2+
3+
#[thrust::requires((x.0 > 0) && (x.1 > 0))]
4+
#[thrust::ensures((result.0 == x.1) && (result.1 == x.0))]
5+
fn swap_positive<T, U>(x: (i32, i32, T, U)) -> (i32, i32, U, T) {
6+
(x.1, x.0, x.3, x.2)
7+
}
8+
9+
fn main() {
10+
let result = swap_positive((-5, 10, true, 42));
11+
assert!(result.0 == 10);
12+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//@error-in-other-file: Unsat
2+
3+
#[thrust::requires(true)]
4+
#[thrust::ensures(result == x)]
5+
fn id<T>(x: T) -> T {
6+
x
7+
}
8+
9+
fn main() {
10+
let a = id(42);
11+
assert!(a == 42);
12+
13+
let b = id(true);
14+
assert!(b == false);
15+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//@error-in-other-file: Unsat
2+
3+
#[thrust::requires(true)]
4+
#[thrust::ensures(result == x)]
5+
fn id<T>(x: T) -> T {
6+
x
7+
}
8+
9+
#[thrust::requires(true)]
10+
#[thrust::ensures(result != x)]
11+
fn apply_twice<T>(x: T) -> T {
12+
id(id(x))
13+
}
14+
15+
fn main() {
16+
assert!(apply_twice(42) == 42);
17+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//@error-in-other-file: Unsat
2+
//@compile-flags: -C debug-assertions=off
3+
4+
#[thrust::requires(n >= 0)]
5+
#[thrust::ensures(result == value)]
6+
fn repeat<T>(n: i32, value: T) -> T {
7+
if n == 0 {
8+
value
9+
} else {
10+
repeat(n - 1, value)
11+
}
12+
}
13+
14+
fn main() {
15+
let result = repeat(-1, 42);
16+
assert!(result == 42);
17+
}

tests/ui/fail/fn_poly_annot_ref.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//@error-in-other-file: Unsat
2+
3+
#[thrust::requires(true)]
4+
#[thrust::ensures(result != x)]
5+
fn id_ref<T>(x: &T) -> &T {
6+
x
7+
}
8+
9+
fn main() {
10+
let val = 42;
11+
let r = id_ref(&val);
12+
assert!(*r == 42);
13+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//@error-in-other-file: Unsat
2+
//@compile-flags: -C debug-assertions=off
3+
4+
#[thrust::requires(x > 0)]
5+
#[thrust::ensures((result == x) && (result > 0))]
6+
fn pass_positive<T>(x: i32, _dummy: T) -> i32 {
7+
x
8+
}
9+
10+
fn main() {
11+
let result = pass_positive(-5, true);
12+
assert!(result == -5);
13+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//@error-in-other-file: Unsat
2+
3+
fn id<T>(x: T) -> T {
4+
x
5+
}
6+
7+
fn apply_twice<T>(x: T) -> T {
8+
id(id(x))
9+
}
10+
11+
fn apply_thrice<T>(x: T) -> T {
12+
apply_twice(id(x))
13+
}
14+
15+
fn apply_four<T>(x: T) -> T {
16+
apply_twice(apply_twice(x))
17+
}
18+
19+
fn main() {
20+
assert!(apply_four(42) == 43);
21+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//@error-in-other-file: Unsat
2+
3+
fn first<T, U>(pair: (T, U)) -> T {
4+
pair.0
5+
}
6+
7+
fn main() {
8+
let x = first((42, true));
9+
let y = first((true, 100));
10+
11+
assert!(x == 42);
12+
assert!(y == false);
13+
}

tests/ui/fail/fn_poly_mut_ref.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//@error-in-other-file: Unsat
2+
3+
fn update<T>(x: &mut T, new_val: T) {
4+
*x = new_val;
5+
}
6+
7+
fn chain_update<T>(x: &mut T, temp: T, final_val: T) {
8+
update(x, temp);
9+
update(x, final_val);
10+
}
11+
12+
fn main() {
13+
let mut val = 42;
14+
chain_update(&mut val, 100, 200);
15+
assert!(val == 42);
16+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//@error-in-other-file: Unsat
2+
3+
fn id<T>(x: T) -> T {
4+
x
5+
}
6+
7+
fn apply_twice<T>(x: T) -> T {
8+
id(id(x))
9+
}
10+
11+
fn apply_thrice<T>(x: T) -> T {
12+
id(apply_twice(x))
13+
}
14+
15+
fn main() {
16+
assert!(apply_thrice(42) == 43);
17+
}

0 commit comments

Comments
 (0)