Skip to content

Help with FnMut closures capturing mutable references #1392

Answered by jhjourdan
ia0 asked this question in Help
Discussion options

You must be logged in to vote

Your example reveals several problems in Creusot, thanks!

1- The annotation we would like to write is:

#[requires((*r)@ < 42)]
#[ensures((*old(r))@ == (*r)@ + 1)]
|| *r += 1

However, for some reason, the borrow checker refuses it. It seems like variables used in old are not ignored by the borrow checker. I just reported it as #1396.

But in fact, in this simple case, we don't need an annotation, Creusot can infer the specification of he closure. So we can simply remove requires/ensures. But it does not work in you example because...

2- We usually have a static analysis which proves that prophecies of borrows in local variables are constant. But when a borrow is captured in a closure, then …

Replies: 3 comments 3 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
3 replies
@xldenis
Comment options

@jhjourdan
Comment options

@ia0
Comment options

Answer selected by ia0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
3 participants