Skip to content

Commit

Permalink
Statics can also have ensures clauses
Browse files Browse the repository at this point in the history
  • Loading branch information
parno committed Dec 28, 2023
1 parent 9dbb5ca commit 463fd14
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 13 deletions.
11 changes: 1 addition & 10 deletions examples/wip.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
/*
This file models the abstraction of an infinite log that our log
implementation is supposed to implement.
*/
use vstd::set::*;

verus! {

pub struct AbstractInfiniteLogState {
pub head: int,
}
exec static LAZY_X: Lazy<X> ensures LAZY_X.wf() { Lazy::<X>::new() }

} // verus!
3 changes: 1 addition & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -846,15 +846,14 @@ fn to_doc<'a>(
Rule::variant => map_to_doc(ctx, arena, pair),
Rule::union => unsupported(pair),
//Rule::initializer => soft_indent(arena, map_to_doc(ctx, arena, pair)),
Rule::r#const =>
Rule::r#const | Rule::r#static =>
// In this context, if there's an ensures clause, we need to add a line
{
arena.concat(pair.into_inner().map(|p| match p.as_rule() {
Rule::ensures_clause => to_doc(ctx, p, arena).append(arena.line()),
_ => to_doc(ctx, p, arena),
}))
}
Rule::r#static => map_to_doc(ctx, arena, pair),
Rule::r#trait => map_to_doc(ctx, arena, pair),
Rule::trait_alias => unsupported(pair),
Rule::assoc_items => map_to_doc_lines(ctx, arena, pair),
Expand Down
2 changes: 1 addition & 1 deletion src/verus.pest
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,7 @@ const = {
static = {
attr* ~ visibility? ~ fn_mode? ~
static_str ~ mut_str? ~ name ~ colon_str ~ type ~
(eq_str ~ expr)? ~ semi_str
(((eq_str ~ expr)? ~ semi_str) | (ensures_clause ~ fn_block_expr))
}

trait = {
Expand Down
9 changes: 9 additions & 0 deletions tests/verus-consistency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1277,6 +1277,8 @@ verus! {
exec static THREAD_COUNT: core::sync::atomic::AtomicUsize = core::sync::atomic::AtomicUsize::new(0);
exec static LAZY_X: Lazy<X> ensures LAZY_X.wf() { Lazy::<X>::new() }
} // verus!
"#;

Expand All @@ -1285,6 +1287,13 @@ exec static THREAD_COUNT: core::sync::atomic::AtomicUsize = core::sync::atomic::
exec static THREAD_COUNT: core::sync::atomic::AtomicUsize = core::sync::atomic::AtomicUsize::new(0);
exec static LAZY_X: Lazy<X>
ensures
LAZY_X.wf(),
{
Lazy::<X>::new()
}
} // verus!
"###);
}

0 comments on commit 463fd14

Please sign in to comment.