Skip to content

Commit

Permalink
Fix parser for assume_specification (#115)
Browse files Browse the repository at this point in the history
Fixes #114
  • Loading branch information
jaybosamiya-ms authored Jan 15, 2025
1 parent e75e20f commit 6da8747
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Unreleased

* Fix parser for `assume_specification` to improve support

# v0.5.1

* Add support for `returns` clauses (see [verus#1283](https://github.com/verus-lang/verus/pull/1283))
Expand Down
2 changes: 1 addition & 1 deletion src/verus.pest
Original file line number Diff line number Diff line change
Expand Up @@ -738,8 +738,8 @@ assume_specification = {
generic_param_list? ~
lbracket_str ~ assume_specification_for ~ rbracket_str ~
param_list ~
where_clause? ~
ret_type? ~
where_clause? ~
fn_qualifier ~
semi_str
}
Expand Down
29 changes: 29 additions & 0 deletions tests/verus-consistency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2654,6 +2654,20 @@ pub assume_specification<T, const N: usize> [ <[T; N]>::as_slice ](ar: &[T; N])
ensures
ar@ == out@;
pub assume_specification<Key, Value, S>[HashMap::<Key, Value, S>::insert](
m: &mut HashMap<Key, Value, S>,
k: Key,
v: Value,
) -> (result: Option<Value>) where Key: Eq + Hash, S: BuildHasher
ensures
obeys_key_model::<Key>() && builds_valid_hashers::<S>() ==> {
&&& m@ == old(m)@.insert(k, v)
&&& match result {
Some(v) => old(m)@.contains_key(k) && v == old(m)[k],
None => !old(m)@.contains_key(k),
}
};
} // verus!
"#;
assert_snapshot!(parse_and_format(file).unwrap(), @r"
Expand All @@ -2664,6 +2678,21 @@ pub assume_specification<T, const N: usize> [ <[T; N]>::as_slice ](ar: &[T; N])
ar@ == out@,
;
pub assume_specification<Key, Value, S>[ HashMap::<Key, Value, S>::insert ](
m: &mut HashMap<Key, Value, S>,
k: Key,
v: Value,
) -> (result: Option<Value>) where Key: Eq + Hash, S: BuildHasher
ensures
obeys_key_model::<Key>() && builds_valid_hashers::<S>() ==> {
&&& m@ == old(m)@.insert(k, v)
&&& match result {
Some(v) => old(m)@.contains_key(k) && v == old(m)[k],
None => !old(m)@.contains_key(k),
}
},
;
} // verus!
")
}
Expand Down

0 comments on commit 6da8747

Please sign in to comment.