Skip to content

Commit

Permalink
Merge pull request #1264 from arnaudgolfouse/snapshot-ghost
Browse files Browse the repository at this point in the history
`snapshot!` in ghost
  • Loading branch information
arnaudgolfouse authored Nov 28, 2024
2 parents 244fefa + 21f5931 commit f2f2ecb
Show file tree
Hide file tree
Showing 7 changed files with 123 additions and 5 deletions.
1 change: 1 addition & 0 deletions creusot-contracts/src/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ impl<T: View + ?Sized> View for Snapshot<T> {
}

impl<T: ?Sized> Clone for Snapshot<T> {
#[pure]
#[ensures(result == *self)]
fn clone(&self) -> Self {
snapshot! { **self }
Expand Down
1 change: 1 addition & 0 deletions creusot-contracts/src/stubs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ pub fn variant_check<R: crate::well_founded::WellFounded + ?Sized>(_: R) -> Box<
#[rustc_diagnostic_item = "closure_result_constraint"]
pub fn closure_result<R: ?Sized>(_: R, _: R) {}

#[crate::pure]
#[creusot::no_translate]
#[rustc_diagnostic_item = "snapshot_from_fn"]
pub fn snapshot_from_fn<T: ?Sized, F: Fn() -> crate::Snapshot<T>>(_: F) -> crate::Snapshot<T> {
Expand Down
10 changes: 5 additions & 5 deletions creusot/tests/creusot-contracts/creusot-contracts.coma

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

80 changes: 80 additions & 0 deletions creusot/tests/should_succeed/ghost/snapshot_in_ghost.coma

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions creusot/tests/should_succeed/ghost/snapshot_in_ghost.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
extern crate creusot_contracts;
use creusot_contracts::*;

// Check that we can make snapshots in ghost code.
pub fn foo() {
ghost! {
let x = snapshot!(1);
proof_assert!(*x == 1);
};
}

// Check that we can make snapshots in pure functions.
#[pure]
pub fn is_pure() {
let x = snapshot!(1);
proof_assert!(*x == 1);
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.

0 comments on commit f2f2ecb

Please sign in to comment.