Skip to content

Commit

Permalink
Add a test
Browse files Browse the repository at this point in the history
  • Loading branch information
zgrannan committed Nov 28, 2023
1 parent eb1dfd0 commit 94f99b4
Showing 1 changed file with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
use prusti_contracts::*;

#[extern_spec]
impl<T> std::option::Option<T> {
#[pure] // <=== Error triggered by this
#[requires(self.is_some())]
#[ensures(old(self) === Some(result))]
pub fn unwrap(self) -> T; //~ ERROR old expressions should not appear in the postconditions of pure functions

#[pure]
#[ensures(result == matches!(self, Some(_)))]
pub const fn is_some(&self) -> bool;
}

#[pure]
#[requires(x.is_some())]
fn test(x: Option<i32>) -> i32 {
// Following error is due to stub encoding of invalid external spec for function `unwrap()`
x.unwrap() // ~ ERROR precondition of pure function call might not hold
}

fn main() { }

0 comments on commit 94f99b4

Please sign in to comment.