Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #5800
Description
used to be translated to
but the
&mut self
is a long-lived mutable borrow, so anything else that could mutate "this" during the duration of this long-lived mutable borrow could end up being moved around by the compiler. Therefore, given the Dafny semantics, it's not sound to have long-term mutable borrows as Dafny references are never exclusive.Now, the above code is rewritten to
In short, here are the breaking fixes
read_field!(rd!(ref).field)
modify_field!(rd!(ref).field, value)
Field<_>
, a type synonym ofUnsafeCell
&mut self
as first parameter, only&self
so that the compiler won't assume there is only one mutable borrow at a time.How has this been tested?
A new test (
avoid_soundness_mut
) that was emitting at least one "Soundness Issue" now emits "Correct" with this fix.Considerations.
I think it's worth piggy-backing on this soundness issue to revisiting the concept of "object" with this. Indeed, it used to be that the struct was wrapped in
UnsafeCell
because of potential mutation, but this soundness issue demonstrated that this is not sufficient. Hence, the new type of object could be simply:By submitting this pull request, I confirm that my contribution is made under the terms of the MIT license.