Skip to content

Commit 7bd8248

Browse files
committed
Fix test.
1 parent c153d2c commit 7bd8248

1 file changed

Lines changed: 19 additions & 12 deletions

File tree

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)