Skip to content

Conversation

@Chris-Hawblitzel
Copy link
Collaborator

Revise #1704 (see comments there for more details)

By submitting this pull request, I confirm that my contribution is made under the terms of the MIT license.

zeldovich and others added 2 commits June 21, 2025 12:45
Without this fix, trying to verify a simple program like:

        let m = HashSet::<u32>::new();
        for k in m.iter() {}

would lead to an error:

        error: loop invariant not satisfied
         --> bug.rs:9:9
          |
        9 |         for k in m.iter() {}
          |         ^^^^^^^^^^^^^^^^^^^^
          |         |
          |         at this loop exit
          |         failed this invariant

        verification results:: 1 verified, 1 errors
        error: aborting due to 1 previous error

but if m.iter() was instead an identifier, as in below, verification passed:

        let m = HashSet::<u32>::new();
        let m_iter = m.iter();
        for k in m_iter {}

This commit changes the for loop macro to avoid evaluating the iterator
expression, such as m.iter() in the above example, multiple times, which
makes the first example above verify just fine.
@Chris-Hawblitzel Chris-Hawblitzel merged commit 4053e1d into loop-infer-base Jun 21, 2025
11 checks passed
@Chris-Hawblitzel Chris-Hawblitzel deleted the loop-infer-revised branch June 21, 2025 20:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants