Skip to content

Commit

Permalink
Fix test.
Browse files Browse the repository at this point in the history
  • Loading branch information
vakaras committed Jul 20, 2023
1 parent c153d2c commit 7bd8248
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions prusti-tests/tests/verify_overflow/pass/extern-spec/linked-list.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![feature(allocator_api)]

use prusti_contracts::*;

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

#[extern_spec]
impl<T> LinkedList<T>
impl<T> LinkedList<T, std::alloc::Global>
where T: Copy + PartialEq {
#[ensures(result.is_empty())]
pub fn new() -> LinkedList<T>;
pub fn new() -> LinkedList<T, std::alloc::Global>;

#[ensures(self.len() == old(self.len() + other.len()))]
#[ensures(forall (|i: usize| (i < old(self.len())) ==>
get(self, i) == old(get(self, i))))]
#[ensures(forall (|j: usize| (old(self.len()) <= j && j < self.len()) ==>
get(self, j) == old(get(other, j - self.len()))))]
#[ensures(other.len() == 0)]
pub fn append(&mut self, other: &mut LinkedList<T, std::alloc::Global>);
}

#[extern_spec]
impl<T, A> LinkedList<T, A>
where T: Copy + PartialEq,
A: std::alloc::Allocator + Clone {
#[pure]
#[ensures(result ==> self.len() == 0)]
#[ensures(!result ==> self.len() > 0)]
Expand Down Expand Up @@ -74,22 +89,14 @@ impl<T> LinkedList<T>
get(self, i) == old(get(self, i))))]
pub fn pop_back(&mut self) -> Option<T>;

#[ensures(self.len() == old(self.len() + other.len()))]
#[ensures(forall (|i: usize| (i < old(self.len())) ==>
get(self, i) == old(get(self, i))))]
#[ensures(forall (|j: usize| (old(self.len()) <= j && j < self.len()) ==>
get(self, j) == old(get(other, j - self.len()))))]
#[ensures(other.len() == 0)]
pub fn append(&mut self, other: &mut LinkedList<T>);

#[requires(at <= self.len())]
#[ensures(result.len() == old(self.len()) - at)]
#[ensures(self.len() == at)]
#[ensures(forall (|i: usize| (i < self.len()) ==>
get(self, i) == old(get(self, i))))]
#[ensures(forall (|j: usize| (j < result.len()) ==>
get(&result, j) == old(get(self, j + at))))]
pub fn split_off(&mut self, at: usize) -> LinkedList<T>;
pub fn split_off(&mut self, at: usize) -> LinkedList<T, A>;
}

fn main() {
Expand Down

0 comments on commit 7bd8248

Please sign in to comment.