Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix parser for assume_specification #115

Merged
merged 1 commit into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading