From 7bd8248fcf7e5c90d96de3bb2fb092454ed7fa6c Mon Sep 17 00:00:00 2001 From: Vytautas Astrauskas Date: Thu, 20 Jul 2023 11:56:04 +0200 Subject: [PATCH] Fix test. --- .../pass/extern-spec/linked-list.rs | 31 ++++++++++++------- 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/prusti-tests/tests/verify_overflow/pass/extern-spec/linked-list.rs b/prusti-tests/tests/verify_overflow/pass/extern-spec/linked-list.rs index b42998e2fd0..d502713c4cd 100644 --- a/prusti-tests/tests/verify_overflow/pass/extern-spec/linked-list.rs +++ b/prusti-tests/tests/verify_overflow/pass/extern-spec/linked-list.rs @@ -1,3 +1,5 @@ +#![feature(allocator_api)] + use prusti_contracts::*; use std::collections::LinkedList; @@ -24,7 +26,7 @@ impl std::option::Option { #[trusted] #[pure] #[requires(index < list.len())] -fn get(list: &LinkedList, index: usize) -> T { +fn get(list: &LinkedList, index: usize) -> T { for (i, elem) in list.iter().enumerate() { if i == index { return *elem; @@ -34,11 +36,24 @@ fn get(list: &LinkedList, index: usize) -> T { } #[extern_spec] -impl LinkedList +impl LinkedList where T: Copy + PartialEq { #[ensures(result.is_empty())] - pub fn new() -> LinkedList; + pub fn new() -> LinkedList; + + #[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); +} +#[extern_spec] +impl LinkedList + where T: Copy + PartialEq, + A: std::alloc::Allocator + Clone { #[pure] #[ensures(result ==> self.len() == 0)] #[ensures(!result ==> self.len() > 0)] @@ -74,14 +89,6 @@ impl LinkedList get(self, i) == old(get(self, i))))] pub fn pop_back(&mut self) -> Option; - #[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); - #[requires(at <= self.len())] #[ensures(result.len() == old(self.len()) - at)] #[ensures(self.len() == at)] @@ -89,7 +96,7 @@ impl LinkedList 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; + pub fn split_off(&mut self, at: usize) -> LinkedList; } fn main() {