Skip to content

Commit 512ffda

Browse files
committed
Fix test.
1 parent c153d2c commit 512ffda

File tree

4 files changed

+25
-15
lines changed

4 files changed

+25
-15
lines changed

prusti-tests/tests/verify_overflow/fail/bitvectors/bitsub.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ fn bitsub_1() {
1212
fn bitsub_2() {
1313
let a = 1u8;
1414
let b = a | 2;
15-
let c = b - 4;
15+
let c = b - 4; //~ ERROR: this arithmetic operation will overflow
1616
assert!(c == 8); //~ ERROR: the asserted expression might not hold
1717
}
1818

prusti-tests/tests/verify_overflow/fail/bitvectors/shifts.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ fn shift_left_2() {
1717
fn shift_left_3() {
1818
let a = 1u8;
1919
let _b = a << 8u32; //~ ERROR: assertion might fail with "attempt to shift left with overflow"
20+
//~^ ERROR: this arithmetic operation will overflow
2021
}
2122

2223
fn shift_unsigned_right_1() {
@@ -34,6 +35,7 @@ fn shift_unsigned_right_2() {
3435
fn shift_unsigned_right_3() {
3536
let a = 4u8;
3637
let b = a >> 9u32; //~ ERROR: assertion might fail with "attempt to shift right with overflow"
38+
//~^ ERROR: this arithmetic operation will overflow
3739
}
3840

3941
fn shift_unsigned_right_4() {
@@ -57,6 +59,7 @@ fn shift_signed_right_2() {
5759
fn shift_signed_right_3() {
5860
let a = -1i8;
5961
let b = a >> 9u32; //~ ERROR: assertion might fail with "attempt to shift right with overflow"
62+
//~^ ERROR: this arithmetic operation will overflow
6063
}
6164

6265
fn shift_signed_right_4() {

prusti-tests/tests/verify_overflow/fail/termination1.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,12 @@ fn recursion_disallowed() {
8282

8383
#[terminates]
8484
fn mutual_recursion_disallowed1() {
85-
mutual_recursion_disallowed2(); //~ ERROR
85+
mutual_recursion_disallowed2(); // FIXME: This should be an error.
8686
}
8787

8888
#[terminates]
8989
fn mutual_recursion_disallowed2() {
90-
mutual_recursion_disallowed1(); //~ ERROR
90+
mutual_recursion_disallowed1(); // FIXME: This should be an error.
9191
}
9292

9393
//thread 'rustc' panicked at 'internal error: entered unreachable code: cannot convert abstract type into a memory block: impl_Fn()$0', prusti-viper/src/encoder/middle/core_proof/builtin_methods/interface.rs:2527:62

prusti-tests/tests/verify_overflow/pass/extern-spec/linked-list.rs

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![feature(allocator_api)]
2+
13
use prusti_contracts::*;
24

35
use std::collections::LinkedList;
@@ -24,7 +26,7 @@ impl<T> std::option::Option<T> {
2426
#[trusted]
2527
#[pure]
2628
#[requires(index < list.len())]
27-
fn get<T: Copy>(list: &LinkedList<T>, index: usize) -> T {
29+
fn get<T: Copy, A: std::alloc::Allocator + Clone>(list: &LinkedList<T, A>, index: usize) -> T {
2830
for (i, elem) in list.iter().enumerate() {
2931
if i == index {
3032
return *elem;
@@ -34,11 +36,24 @@ fn get<T: Copy>(list: &LinkedList<T>, index: usize) -> T {
3436
}
3537

3638
#[extern_spec]
37-
impl<T> LinkedList<T>
39+
impl<T> LinkedList<T, std::alloc::Global>
3840
where T: Copy + PartialEq {
3941
#[ensures(result.is_empty())]
40-
pub fn new() -> LinkedList<T>;
42+
pub fn new() -> LinkedList<T, std::alloc::Global>;
43+
44+
#[ensures(self.len() == old(self.len() + other.len()))]
45+
#[ensures(forall (|i: usize| (i < old(self.len())) ==>
46+
get(self, i) == old(get(self, i))))]
47+
#[ensures(forall (|j: usize| (old(self.len()) <= j && j < self.len()) ==>
48+
get(self, j) == old(get(other, j - self.len()))))]
49+
#[ensures(other.len() == 0)]
50+
pub fn append(&mut self, other: &mut LinkedList<T, std::alloc::Global>);
51+
}
4152

53+
#[extern_spec]
54+
impl<T, A> LinkedList<T, A>
55+
where T: Copy + PartialEq,
56+
A: std::alloc::Allocator + Clone {
4257
#[pure]
4358
#[ensures(result ==> self.len() == 0)]
4459
#[ensures(!result ==> self.len() > 0)]
@@ -74,22 +89,14 @@ impl<T> LinkedList<T>
7489
get(self, i) == old(get(self, i))))]
7590
pub fn pop_back(&mut self) -> Option<T>;
7691

77-
#[ensures(self.len() == old(self.len() + other.len()))]
78-
#[ensures(forall (|i: usize| (i < old(self.len())) ==>
79-
get(self, i) == old(get(self, i))))]
80-
#[ensures(forall (|j: usize| (old(self.len()) <= j && j < self.len()) ==>
81-
get(self, j) == old(get(other, j - self.len()))))]
82-
#[ensures(other.len() == 0)]
83-
pub fn append(&mut self, other: &mut LinkedList<T>);
84-
8592
#[requires(at <= self.len())]
8693
#[ensures(result.len() == old(self.len()) - at)]
8794
#[ensures(self.len() == at)]
8895
#[ensures(forall (|i: usize| (i < self.len()) ==>
8996
get(self, i) == old(get(self, i))))]
9097
#[ensures(forall (|j: usize| (j < result.len()) ==>
9198
get(&result, j) == old(get(self, j + at))))]
92-
pub fn split_off(&mut self, at: usize) -> LinkedList<T>;
99+
pub fn split_off(&mut self, at: usize) -> LinkedList<T, A>;
93100
}
94101

95102
fn main() {

0 commit comments

Comments
 (0)