-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
do not trust predicate functions when opting in to verification plus …
- Loading branch information
1 parent
4015f56
commit 90373f1
Showing
3 changed files
with
51 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
prusti-tests/tests/verify_overflow/fail/issues/issue-1187-4.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// compile-flags: -Popt_in_verification=true -Penable_type_invariants=true | ||
use prusti_contracts::*; | ||
|
||
fn main() {} | ||
|
||
#[derive(Copy, Clone)] | ||
#[invariant(self.bar > 0)] | ||
pub struct Foo { | ||
pub bar: usize, | ||
} | ||
|
||
impl Foo { | ||
#[verified] | ||
pub const fn new(bar: usize) -> Self { | ||
//~^ ERROR type invariants might not hold | ||
Self { bar } | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
prusti-tests/tests/verify_overflow/pass/issues/issue-1187-5.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// compile-flags: -Popt_in_verification=true | ||
use prusti_contracts::*; | ||
|
||
fn main() {} | ||
|
||
predicate! { | ||
fn baz(foo: &Foo) -> bool { | ||
foo.bar > 0 | ||
} | ||
} | ||
|
||
#[derive(Copy, Clone)] | ||
pub struct Foo { | ||
pub bar: usize, | ||
} | ||
|
||
impl Foo { | ||
#[verified] | ||
#[pure] | ||
#[ensures(match result { | ||
Some(foo) => baz(&foo), | ||
None => true, | ||
})] | ||
pub const fn new(bar: usize) -> Option<Self> { | ||
if bar > 0 { | ||
Some(Self { bar }) | ||
} else { | ||
None | ||
} | ||
} | ||
} |